@letsscrapedata/controller 0.0.31 → 0.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +22 -31
- package/dist/index.d.cts +29 -27
- package/dist/index.d.ts +29 -27
- package/dist/index.js +21 -29
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -58,21 +58,10 @@ __export(src_exports, {
|
|
|
58
58
|
PuppeteerBrowserContext: () => PuppeteerBrowserContext,
|
|
59
59
|
PuppeteerElement: () => PuppeteerElement,
|
|
60
60
|
PuppeteerPage: () => PuppeteerPage,
|
|
61
|
-
controller: () => controller
|
|
62
|
-
defaultProxy: () => defaultProxy
|
|
61
|
+
controller: () => controller
|
|
63
62
|
});
|
|
64
63
|
module.exports = __toCommonJS(src_exports);
|
|
65
64
|
|
|
66
|
-
// src/types/types.ts
|
|
67
|
-
var defaultProxy = {
|
|
68
|
-
server: "default",
|
|
69
|
-
proxyIpType: "residential",
|
|
70
|
-
proxyDurationType: "static",
|
|
71
|
-
proxySharedType: "dedicated",
|
|
72
|
-
expireTime: 41024196e5
|
|
73
|
-
// "2100-01-01 01:00:00"
|
|
74
|
-
};
|
|
75
|
-
|
|
76
65
|
// src/playwright/browser.ts
|
|
77
66
|
var import_node_events3 = __toESM(require("events"), 1);
|
|
78
67
|
|
|
@@ -179,8 +168,8 @@ var PlaywrightElement = class _PlaywrightElement {
|
|
|
179
168
|
}
|
|
180
169
|
try {
|
|
181
170
|
let locators = [];
|
|
182
|
-
if (selector.startsWith("./") || selector.startsWith("/")) {
|
|
183
|
-
locators = await parent2.locator(selector).all();
|
|
171
|
+
if (selector.startsWith("./") || selector.startsWith("/") || selector.startsWith("..")) {
|
|
172
|
+
locators = await parent2.locator(`xpath=${selector}`).all();
|
|
184
173
|
} else {
|
|
185
174
|
if (selector !== ".") {
|
|
186
175
|
locators = await parent2.locator(selector).all();
|
|
@@ -524,8 +513,8 @@ var PlaywrightPage = class extends import_node_events.default {
|
|
|
524
513
|
}
|
|
525
514
|
try {
|
|
526
515
|
let locators = [];
|
|
527
|
-
if (selector.startsWith("./") || selector.startsWith("/")) {
|
|
528
|
-
locators = await frame.locator(selector).all();
|
|
516
|
+
if (selector.startsWith("./") || selector.startsWith("/") || selector.startsWith("..")) {
|
|
517
|
+
locators = await frame.locator(`xpath=${selector}`).all();
|
|
529
518
|
} else {
|
|
530
519
|
if (selector !== ".") {
|
|
531
520
|
locators = await frame.locator(selector).all();
|
|
@@ -1234,7 +1223,7 @@ var PlaywrightBrowserContext = class extends import_node_events2.default {
|
|
|
1234
1223
|
this.#browserContext = browserContext;
|
|
1235
1224
|
this.#createTime = (0, import_utils3.getCurrentUnixTime)();
|
|
1236
1225
|
this.#incognito = incognito === false ? false : true;
|
|
1237
|
-
this.#proxy = proxy?.
|
|
1226
|
+
this.#proxy = proxy?.proxyUrl ? proxy : null;
|
|
1238
1227
|
this.#maxPagesPerBrowserContext = maxPagesPerBrowserContext;
|
|
1239
1228
|
this.#maxPageFreeSeconds = maxPageFreeSeconds;
|
|
1240
1229
|
this.#maxViewportOfNewPage = maxViewportOfNewPage;
|
|
@@ -1543,7 +1532,7 @@ var PlaywrightBrowser = class extends import_node_events3.default {
|
|
|
1543
1532
|
}
|
|
1544
1533
|
const proxy = options?.proxy ? Object.assign({}, options.proxy) : this.#proxy;
|
|
1545
1534
|
if (proxy) {
|
|
1546
|
-
const { server, username, password } = proxy;
|
|
1535
|
+
const { proxyUrl: server, username, password } = proxy;
|
|
1547
1536
|
browserContextOptions.proxy = { server, username, password };
|
|
1548
1537
|
}
|
|
1549
1538
|
if (options?.userAgent) {
|
|
@@ -1687,11 +1676,13 @@ var PuppeteerElement = class _PuppeteerElement {
|
|
|
1687
1676
|
return retObj;
|
|
1688
1677
|
}
|
|
1689
1678
|
retObj.frame = frame;
|
|
1679
|
+
absolute = true;
|
|
1690
1680
|
parent2 = frame;
|
|
1691
1681
|
}
|
|
1692
1682
|
try {
|
|
1693
|
-
if (selector.startsWith("./") || selector.startsWith("/")) {
|
|
1694
|
-
|
|
1683
|
+
if (selector.startsWith("./") || selector.startsWith("/") || selector.startsWith("..")) {
|
|
1684
|
+
const newSelector = !absolute && selector.startsWith("/") ? `.${selector}` : selector;
|
|
1685
|
+
retObj.elementHandles = await parent2.$$(`::-p-xpath(${newSelector})`);
|
|
1695
1686
|
} else {
|
|
1696
1687
|
if (selector !== ".") {
|
|
1697
1688
|
retObj.elementHandles = await parent2.$$(selector);
|
|
@@ -2013,8 +2004,8 @@ var PuppeteerPage = class extends import_node_events4.default {
|
|
|
2013
2004
|
retObj.frame = frame;
|
|
2014
2005
|
}
|
|
2015
2006
|
try {
|
|
2016
|
-
if (selector.startsWith("./") || selector.startsWith("/")) {
|
|
2017
|
-
retObj.elementHandles = await frame.$$(selector);
|
|
2007
|
+
if (selector.startsWith("./") || selector.startsWith("/") || selector.startsWith("..")) {
|
|
2008
|
+
retObj.elementHandles = await frame.$$(`::-p-xpath(${selector})`);
|
|
2018
2009
|
} else {
|
|
2019
2010
|
if (selector !== ".") {
|
|
2020
2011
|
retObj.elementHandles = await frame.$$(selector);
|
|
@@ -2717,7 +2708,7 @@ var PuppeteerBrowserContext = class extends import_node_events5.default {
|
|
|
2717
2708
|
this.#userAgent = userAgent;
|
|
2718
2709
|
this.#createTime = (0, import_utils7.getCurrentUnixTime)();
|
|
2719
2710
|
this.#incognito = incognito === false ? false : true;
|
|
2720
|
-
this.#proxy = proxy?.
|
|
2711
|
+
this.#proxy = proxy?.proxyUrl ? proxy : null;
|
|
2721
2712
|
this.#maxPagesPerBrowserContext = maxPagesPerBrowserContext;
|
|
2722
2713
|
this.#maxPageFreeSeconds = maxPageFreeSeconds;
|
|
2723
2714
|
this.#maxViewportOfNewPage = maxViewportOfNewPage;
|
|
@@ -3030,8 +3021,8 @@ var PuppeteerBrowser = class extends import_node_events6.default {
|
|
|
3030
3021
|
}
|
|
3031
3022
|
const browserContextOptions = {};
|
|
3032
3023
|
const proxy = options?.proxy ? Object.assign({}, options.proxy) : this.#proxy;
|
|
3033
|
-
if (proxy?.
|
|
3034
|
-
browserContextOptions.proxyServer = proxy.
|
|
3024
|
+
if (proxy?.proxyUrl) {
|
|
3025
|
+
browserContextOptions.proxyServer = proxy.proxyUrl;
|
|
3035
3026
|
}
|
|
3036
3027
|
const browserContext = await this.#browser.createBrowserContext(browserContextOptions);
|
|
3037
3028
|
const userAgent = options?.userAgent ? options.userAgent : "";
|
|
@@ -17388,8 +17379,9 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17388
17379
|
if (maxWindowSize) {
|
|
17389
17380
|
args.push("--start-maximized");
|
|
17390
17381
|
}
|
|
17391
|
-
if (proxy?.
|
|
17392
|
-
|
|
17382
|
+
if (proxy?.proxyUrl && proxy.proxyUrl !== "local") {
|
|
17383
|
+
const { proxyUrl: server, username, password } = proxy;
|
|
17384
|
+
launchOptions.proxy = { server, username, password };
|
|
17393
17385
|
} else if (proxyPerBrowserContext && browserType === "chromium" && this.#osPlatform.startsWith("win")) {
|
|
17394
17386
|
launchOptions.proxy = { server: "proxyPerBrowserContext" };
|
|
17395
17387
|
}
|
|
@@ -17428,8 +17420,8 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17428
17420
|
} else if (userDataDir) {
|
|
17429
17421
|
args.push(`--user-data-dir=${userDataDir}`);
|
|
17430
17422
|
}
|
|
17431
|
-
if (proxy?.
|
|
17432
|
-
args.push(`--proxy-server=${proxy.
|
|
17423
|
+
if (proxy?.proxyUrl && proxy.proxyUrl !== "default") {
|
|
17424
|
+
args.push(`--proxy-server=${proxy.proxyUrl}`);
|
|
17433
17425
|
} else if (proxyPerBrowserContext && browserType === "chromium" && this.#osPlatform.startsWith("win")) {
|
|
17434
17426
|
args.push(`--proxy-server=proxyPerBrowserContext`);
|
|
17435
17427
|
}
|
|
@@ -17502,6 +17494,5 @@ var controller = new LsdBrowserController();
|
|
|
17502
17494
|
PuppeteerBrowserContext,
|
|
17503
17495
|
PuppeteerElement,
|
|
17504
17496
|
PuppeteerPage,
|
|
17505
|
-
controller
|
|
17506
|
-
defaultProxy
|
|
17497
|
+
controller
|
|
17507
17498
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -17,22 +17,11 @@ type AllPage = Page | Page$1;
|
|
|
17
17
|
type AllResponse = Response | HTTPResponse;
|
|
18
18
|
type AllApiRequestContext = APIRequestContext;
|
|
19
19
|
type CheerioNode = cheerio.Cheerio<cheerio.Element>;
|
|
20
|
-
type
|
|
21
|
-
|
|
20
|
+
type ProxyInController = {
|
|
21
|
+
proxyUrl: string;
|
|
22
22
|
username?: string;
|
|
23
23
|
password?: string;
|
|
24
24
|
proxyId?: string;
|
|
25
|
-
host?: string;
|
|
26
|
-
port?: number;
|
|
27
|
-
expireTime?: number;
|
|
28
|
-
proxyIpType?: string;
|
|
29
|
-
proxyDurationType?: string;
|
|
30
|
-
proxySharedType?: string;
|
|
31
|
-
latitude?: number;
|
|
32
|
-
longitude?: number;
|
|
33
|
-
freeable?: boolean;
|
|
34
|
-
interfaceName?: string;
|
|
35
|
-
packageName?: string;
|
|
36
25
|
};
|
|
37
26
|
type BrowserControllerType = "puppeteer" | "playwright";
|
|
38
27
|
type BrowserCreationMethod = "launch" | "connect";
|
|
@@ -45,7 +34,6 @@ interface PlaywrightBrowserTypes {
|
|
|
45
34
|
type BrowserControllerOptions = {
|
|
46
35
|
browserControllerType: BrowserControllerType;
|
|
47
36
|
};
|
|
48
|
-
declare const defaultProxy: Proxy;
|
|
49
37
|
interface BrowserOptions {
|
|
50
38
|
/**
|
|
51
39
|
* Interval between closing free pages (seconds) if greater than 0
|
|
@@ -76,7 +64,7 @@ interface BrowserOptions {
|
|
|
76
64
|
* * this will used as default proxy when creating new browserContexts later
|
|
77
65
|
* @default null
|
|
78
66
|
*/
|
|
79
|
-
proxy?:
|
|
67
|
+
proxy?: ProxyInController | null;
|
|
80
68
|
/**
|
|
81
69
|
* Maximum time in milliseconds to wait for the browser instance to start. Pass 0 to disable timeout.
|
|
82
70
|
* * default 30_000 (30 seconds)
|
|
@@ -143,7 +131,7 @@ interface LsdConnectOptions extends BrowserOptions {
|
|
|
143
131
|
userAgent?: string;
|
|
144
132
|
}
|
|
145
133
|
type LsdBrowserContextOptions = {
|
|
146
|
-
proxy:
|
|
134
|
+
proxy: ProxyInController | null;
|
|
147
135
|
/**
|
|
148
136
|
* @default browser.options.maxViewportOfNewPage
|
|
149
137
|
*/
|
|
@@ -154,7 +142,6 @@ type LsdBrowserContextOptions = {
|
|
|
154
142
|
* * puppeteer: set when creating the new page in the browserContext
|
|
155
143
|
*/
|
|
156
144
|
userAgent?: string;
|
|
157
|
-
fingerPrint: Object;
|
|
158
145
|
};
|
|
159
146
|
type PageStatus = "free" | "busy" | "closed";
|
|
160
147
|
/**
|
|
@@ -875,6 +862,10 @@ interface LsdPage extends EventEmitter {
|
|
|
875
862
|
* @param stateData
|
|
876
863
|
*/
|
|
877
864
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
865
|
+
/**
|
|
866
|
+
* valid only in puppeteer
|
|
867
|
+
* @param userAgent
|
|
868
|
+
*/
|
|
878
869
|
setUserAgent(userAgent: string): Promise<boolean>;
|
|
879
870
|
setViewportSize(viewPortSize: ViewportSize): Promise<boolean>;
|
|
880
871
|
stateData(): Promise<StateData>;
|
|
@@ -913,30 +904,41 @@ interface LsdBrowserContext extends EventEmitter {
|
|
|
913
904
|
*/
|
|
914
905
|
closeFreePages(maxPageFreeSeconds?: number): Promise<boolean>;
|
|
915
906
|
/**
|
|
916
|
-
*
|
|
917
|
-
* * TBD:需要预留pageQuota给需要capName的TE使用
|
|
907
|
+
* get a free page from current pages or by creating a new page
|
|
918
908
|
*/
|
|
919
909
|
getPage(always?: boolean): Promise<LsdPage | null>;
|
|
920
910
|
/**
|
|
921
|
-
*
|
|
922
|
-
*
|
|
911
|
+
* whether can get a number of free page(s)
|
|
912
|
+
* * refer to getPage()
|
|
913
|
+
* @param pageNum default 1, the number of free pages
|
|
923
914
|
*/
|
|
924
915
|
hasNewPage(pageNum?: number): boolean;
|
|
925
916
|
id(): string;
|
|
926
917
|
isIncognito(): boolean;
|
|
927
918
|
page(pageIdx: number): LsdPage | null;
|
|
928
919
|
pages(): LsdPage[];
|
|
929
|
-
proxy():
|
|
920
|
+
proxy(): ProxyInController | null;
|
|
930
921
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
931
922
|
_origBrowserContext(): AllBrowserContext;
|
|
932
923
|
}
|
|
933
924
|
interface LsdBrowser extends EventEmitter {
|
|
934
925
|
newBrowserContext(options?: LsdBrowserContextOptions): Promise<LsdBrowserContext | null>;
|
|
926
|
+
/**
|
|
927
|
+
* 1. launched: close all browserContexts and this browser
|
|
928
|
+
* 2. connected:
|
|
929
|
+
* * in puppeteer: close all browserContexts and this browser???
|
|
930
|
+
* * in playwright: only browserContexts created by newContext will be closed, browser is disconnected and browser will not be closed
|
|
931
|
+
*/
|
|
935
932
|
close(): Promise<boolean>;
|
|
936
933
|
browserContexts(): LsdBrowserContext[];
|
|
937
934
|
browserControllerType(): BrowserControllerType;
|
|
938
935
|
browserCreationMethod(): BrowserCreationMethod;
|
|
939
936
|
browserType(): LsdBrowserType;
|
|
937
|
+
/**
|
|
938
|
+
* @returns
|
|
939
|
+
* 1. launched: actual executable path
|
|
940
|
+
* 2. connected: exectuablePath in LsdConnectOptions, default ""(unkown)
|
|
941
|
+
*/
|
|
940
942
|
executablePath(): string;
|
|
941
943
|
id(): string;
|
|
942
944
|
isConnected(): boolean;
|
|
@@ -1023,7 +1025,7 @@ declare class PlaywrightBrowser extends EventEmitter implements LsdBrowser {
|
|
|
1023
1025
|
|
|
1024
1026
|
declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowserContext {
|
|
1025
1027
|
#private;
|
|
1026
|
-
constructor(lsdBrowser: LsdBrowser, browserContext: BrowserContext, incognito?: boolean, proxy?:
|
|
1028
|
+
constructor(lsdBrowser: LsdBrowser, browserContext: BrowserContext, incognito?: boolean, proxy?: ProxyInController | null, browserIdx?: number, browserContextIdx?: number, maxPagesPerBrowserContext?: number, maxPageFreeSeconds?: number, maxViewportOfNewPage?: boolean);
|
|
1027
1029
|
browser(): LsdBrowser;
|
|
1028
1030
|
close(): Promise<boolean>;
|
|
1029
1031
|
closeFreePages(maxPageFreeSeconds?: number): Promise<boolean>;
|
|
@@ -1033,7 +1035,7 @@ declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowse
|
|
|
1033
1035
|
isIncognito(): boolean;
|
|
1034
1036
|
page(pageIdx: number): LsdPage | null;
|
|
1035
1037
|
pages(): LsdPage[];
|
|
1036
|
-
proxy():
|
|
1038
|
+
proxy(): ProxyInController | null;
|
|
1037
1039
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
1038
1040
|
_origBrowserContext(): AllBrowserContext;
|
|
1039
1041
|
}
|
|
@@ -1132,7 +1134,7 @@ declare class PuppeteerBrowser extends EventEmitter implements LsdBrowser {
|
|
|
1132
1134
|
|
|
1133
1135
|
declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowserContext {
|
|
1134
1136
|
#private;
|
|
1135
|
-
constructor(lsdBrowser: LsdBrowser, browserContext: BrowserContext$1, incognito?: boolean, proxy?:
|
|
1137
|
+
constructor(lsdBrowser: LsdBrowser, browserContext: BrowserContext$1, incognito?: boolean, proxy?: ProxyInController | null, browserIdx?: number, browserContextIdx?: number, maxPagesPerBrowserContext?: number, maxPageFreeSeconds?: number, userAgent?: string, maxViewportOfNewPage?: boolean);
|
|
1136
1138
|
browser(): LsdBrowser;
|
|
1137
1139
|
close(): Promise<boolean>;
|
|
1138
1140
|
closeFreePages(maxPageFreeSeconds?: number): Promise<boolean>;
|
|
@@ -1142,7 +1144,7 @@ declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowser
|
|
|
1142
1144
|
isIncognito(): boolean;
|
|
1143
1145
|
page(pageIdx: number): LsdPage | null;
|
|
1144
1146
|
pages(): LsdPage[];
|
|
1145
|
-
proxy():
|
|
1147
|
+
proxy(): ProxyInController | null;
|
|
1146
1148
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
1147
1149
|
_origBrowserContext(): AllBrowserContext;
|
|
1148
1150
|
}
|
|
@@ -1310,4 +1312,4 @@ declare class LsdBrowserController implements LsdBrowserController$1 {
|
|
|
1310
1312
|
}
|
|
1311
1313
|
declare const controller: LsdBrowserController;
|
|
1312
1314
|
|
|
1313
|
-
export { type AllApiRequestContext, type AllBrowser, type AllBrowserContext, type AllFrame, type AllPage, type AllResponse, type BrowserControllerOptions, type BrowserControllerType, type BrowserCreationMethod, type BrowserManager, CheerioElement, type CheerioNode, CheerioPage, type CookieItem, type GotoOptions, type IframeOption, type InputOptions, type KeyInput, type KeyPressOptions, type LocalStorageItem, type LocalStorageOrigin, type LowerCasePaperFormat, type LsdBrowser, type LsdBrowserContext, type LsdBrowserContextOptions, type LsdBrowserController$1 as LsdBrowserController, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdLaunchOptions, type LsdPage, type MouseClickOptions, type MouseClickType, type NavigationWaitUntil, type PDFMargin, type PDFOptions, type PageEvent, type PageExtInPlaywright, type PageExtInPuppeteer, type PageInfo, type PageOpenType, type PageStatus, type PaperFormat, PlaywrightBrowser, PlaywrightBrowserContext, type PlaywrightBrowserTypes, PlaywrightElement, PlaywrightPage, type
|
|
1315
|
+
export { type AllApiRequestContext, type AllBrowser, type AllBrowserContext, type AllFrame, type AllPage, type AllResponse, type BrowserControllerOptions, type BrowserControllerType, type BrowserCreationMethod, type BrowserManager, CheerioElement, type CheerioNode, CheerioPage, type CookieItem, type GotoOptions, type IframeOption, type InputOptions, type KeyInput, type KeyPressOptions, type LocalStorageItem, type LocalStorageOrigin, type LowerCasePaperFormat, type LsdBrowser, type LsdBrowserContext, type LsdBrowserContextOptions, type LsdBrowserController$1 as LsdBrowserController, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdLaunchOptions, type LsdPage, type MouseClickOptions, type MouseClickType, type NavigationWaitUntil, type PDFMargin, type PDFOptions, type PageEvent, type PageExtInPlaywright, type PageExtInPuppeteer, type PageInfo, type PageOpenType, type PageStatus, type PaperFormat, PlaywrightBrowser, PlaywrightBrowserContext, type PlaywrightBrowserTypes, PlaywrightElement, PlaywrightPage, type ProxyInController, PuppeteerBrowser, PuppeteerBrowserContext, PuppeteerElement, PuppeteerPage, type RequestInterceptionAction, type RequestInterceptionOption, type RequestMatch, type RequestMethod, type RequestResourceType, type ResponseHandler, type ResponseHandlerOptions, type ResponseInterceptionItem, type ResponseInterceptionOption, type ResponseMatch, type ResponsePageData, type ScreenshotOptions, type SelectOptions, type StateData, type UpdatablePageInfo, type ViewportSize, type WaitElementOptions, type WaitElementState, type WaitNavigationOptions, controller };
|
package/dist/index.d.ts
CHANGED
|
@@ -17,22 +17,11 @@ type AllPage = Page | Page$1;
|
|
|
17
17
|
type AllResponse = Response | HTTPResponse;
|
|
18
18
|
type AllApiRequestContext = APIRequestContext;
|
|
19
19
|
type CheerioNode = cheerio.Cheerio<cheerio.Element>;
|
|
20
|
-
type
|
|
21
|
-
|
|
20
|
+
type ProxyInController = {
|
|
21
|
+
proxyUrl: string;
|
|
22
22
|
username?: string;
|
|
23
23
|
password?: string;
|
|
24
24
|
proxyId?: string;
|
|
25
|
-
host?: string;
|
|
26
|
-
port?: number;
|
|
27
|
-
expireTime?: number;
|
|
28
|
-
proxyIpType?: string;
|
|
29
|
-
proxyDurationType?: string;
|
|
30
|
-
proxySharedType?: string;
|
|
31
|
-
latitude?: number;
|
|
32
|
-
longitude?: number;
|
|
33
|
-
freeable?: boolean;
|
|
34
|
-
interfaceName?: string;
|
|
35
|
-
packageName?: string;
|
|
36
25
|
};
|
|
37
26
|
type BrowserControllerType = "puppeteer" | "playwright";
|
|
38
27
|
type BrowserCreationMethod = "launch" | "connect";
|
|
@@ -45,7 +34,6 @@ interface PlaywrightBrowserTypes {
|
|
|
45
34
|
type BrowserControllerOptions = {
|
|
46
35
|
browserControllerType: BrowserControllerType;
|
|
47
36
|
};
|
|
48
|
-
declare const defaultProxy: Proxy;
|
|
49
37
|
interface BrowserOptions {
|
|
50
38
|
/**
|
|
51
39
|
* Interval between closing free pages (seconds) if greater than 0
|
|
@@ -76,7 +64,7 @@ interface BrowserOptions {
|
|
|
76
64
|
* * this will used as default proxy when creating new browserContexts later
|
|
77
65
|
* @default null
|
|
78
66
|
*/
|
|
79
|
-
proxy?:
|
|
67
|
+
proxy?: ProxyInController | null;
|
|
80
68
|
/**
|
|
81
69
|
* Maximum time in milliseconds to wait for the browser instance to start. Pass 0 to disable timeout.
|
|
82
70
|
* * default 30_000 (30 seconds)
|
|
@@ -143,7 +131,7 @@ interface LsdConnectOptions extends BrowserOptions {
|
|
|
143
131
|
userAgent?: string;
|
|
144
132
|
}
|
|
145
133
|
type LsdBrowserContextOptions = {
|
|
146
|
-
proxy:
|
|
134
|
+
proxy: ProxyInController | null;
|
|
147
135
|
/**
|
|
148
136
|
* @default browser.options.maxViewportOfNewPage
|
|
149
137
|
*/
|
|
@@ -154,7 +142,6 @@ type LsdBrowserContextOptions = {
|
|
|
154
142
|
* * puppeteer: set when creating the new page in the browserContext
|
|
155
143
|
*/
|
|
156
144
|
userAgent?: string;
|
|
157
|
-
fingerPrint: Object;
|
|
158
145
|
};
|
|
159
146
|
type PageStatus = "free" | "busy" | "closed";
|
|
160
147
|
/**
|
|
@@ -875,6 +862,10 @@ interface LsdPage extends EventEmitter {
|
|
|
875
862
|
* @param stateData
|
|
876
863
|
*/
|
|
877
864
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
865
|
+
/**
|
|
866
|
+
* valid only in puppeteer
|
|
867
|
+
* @param userAgent
|
|
868
|
+
*/
|
|
878
869
|
setUserAgent(userAgent: string): Promise<boolean>;
|
|
879
870
|
setViewportSize(viewPortSize: ViewportSize): Promise<boolean>;
|
|
880
871
|
stateData(): Promise<StateData>;
|
|
@@ -913,30 +904,41 @@ interface LsdBrowserContext extends EventEmitter {
|
|
|
913
904
|
*/
|
|
914
905
|
closeFreePages(maxPageFreeSeconds?: number): Promise<boolean>;
|
|
915
906
|
/**
|
|
916
|
-
*
|
|
917
|
-
* * TBD:需要预留pageQuota给需要capName的TE使用
|
|
907
|
+
* get a free page from current pages or by creating a new page
|
|
918
908
|
*/
|
|
919
909
|
getPage(always?: boolean): Promise<LsdPage | null>;
|
|
920
910
|
/**
|
|
921
|
-
*
|
|
922
|
-
*
|
|
911
|
+
* whether can get a number of free page(s)
|
|
912
|
+
* * refer to getPage()
|
|
913
|
+
* @param pageNum default 1, the number of free pages
|
|
923
914
|
*/
|
|
924
915
|
hasNewPage(pageNum?: number): boolean;
|
|
925
916
|
id(): string;
|
|
926
917
|
isIncognito(): boolean;
|
|
927
918
|
page(pageIdx: number): LsdPage | null;
|
|
928
919
|
pages(): LsdPage[];
|
|
929
|
-
proxy():
|
|
920
|
+
proxy(): ProxyInController | null;
|
|
930
921
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
931
922
|
_origBrowserContext(): AllBrowserContext;
|
|
932
923
|
}
|
|
933
924
|
interface LsdBrowser extends EventEmitter {
|
|
934
925
|
newBrowserContext(options?: LsdBrowserContextOptions): Promise<LsdBrowserContext | null>;
|
|
926
|
+
/**
|
|
927
|
+
* 1. launched: close all browserContexts and this browser
|
|
928
|
+
* 2. connected:
|
|
929
|
+
* * in puppeteer: close all browserContexts and this browser???
|
|
930
|
+
* * in playwright: only browserContexts created by newContext will be closed, browser is disconnected and browser will not be closed
|
|
931
|
+
*/
|
|
935
932
|
close(): Promise<boolean>;
|
|
936
933
|
browserContexts(): LsdBrowserContext[];
|
|
937
934
|
browserControllerType(): BrowserControllerType;
|
|
938
935
|
browserCreationMethod(): BrowserCreationMethod;
|
|
939
936
|
browserType(): LsdBrowserType;
|
|
937
|
+
/**
|
|
938
|
+
* @returns
|
|
939
|
+
* 1. launched: actual executable path
|
|
940
|
+
* 2. connected: exectuablePath in LsdConnectOptions, default ""(unkown)
|
|
941
|
+
*/
|
|
940
942
|
executablePath(): string;
|
|
941
943
|
id(): string;
|
|
942
944
|
isConnected(): boolean;
|
|
@@ -1023,7 +1025,7 @@ declare class PlaywrightBrowser extends EventEmitter implements LsdBrowser {
|
|
|
1023
1025
|
|
|
1024
1026
|
declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowserContext {
|
|
1025
1027
|
#private;
|
|
1026
|
-
constructor(lsdBrowser: LsdBrowser, browserContext: BrowserContext, incognito?: boolean, proxy?:
|
|
1028
|
+
constructor(lsdBrowser: LsdBrowser, browserContext: BrowserContext, incognito?: boolean, proxy?: ProxyInController | null, browserIdx?: number, browserContextIdx?: number, maxPagesPerBrowserContext?: number, maxPageFreeSeconds?: number, maxViewportOfNewPage?: boolean);
|
|
1027
1029
|
browser(): LsdBrowser;
|
|
1028
1030
|
close(): Promise<boolean>;
|
|
1029
1031
|
closeFreePages(maxPageFreeSeconds?: number): Promise<boolean>;
|
|
@@ -1033,7 +1035,7 @@ declare class PlaywrightBrowserContext extends EventEmitter implements LsdBrowse
|
|
|
1033
1035
|
isIncognito(): boolean;
|
|
1034
1036
|
page(pageIdx: number): LsdPage | null;
|
|
1035
1037
|
pages(): LsdPage[];
|
|
1036
|
-
proxy():
|
|
1038
|
+
proxy(): ProxyInController | null;
|
|
1037
1039
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
1038
1040
|
_origBrowserContext(): AllBrowserContext;
|
|
1039
1041
|
}
|
|
@@ -1132,7 +1134,7 @@ declare class PuppeteerBrowser extends EventEmitter implements LsdBrowser {
|
|
|
1132
1134
|
|
|
1133
1135
|
declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowserContext {
|
|
1134
1136
|
#private;
|
|
1135
|
-
constructor(lsdBrowser: LsdBrowser, browserContext: BrowserContext$1, incognito?: boolean, proxy?:
|
|
1137
|
+
constructor(lsdBrowser: LsdBrowser, browserContext: BrowserContext$1, incognito?: boolean, proxy?: ProxyInController | null, browserIdx?: number, browserContextIdx?: number, maxPagesPerBrowserContext?: number, maxPageFreeSeconds?: number, userAgent?: string, maxViewportOfNewPage?: boolean);
|
|
1136
1138
|
browser(): LsdBrowser;
|
|
1137
1139
|
close(): Promise<boolean>;
|
|
1138
1140
|
closeFreePages(maxPageFreeSeconds?: number): Promise<boolean>;
|
|
@@ -1142,7 +1144,7 @@ declare class PuppeteerBrowserContext extends EventEmitter implements LsdBrowser
|
|
|
1142
1144
|
isIncognito(): boolean;
|
|
1143
1145
|
page(pageIdx: number): LsdPage | null;
|
|
1144
1146
|
pages(): LsdPage[];
|
|
1145
|
-
proxy():
|
|
1147
|
+
proxy(): ProxyInController | null;
|
|
1146
1148
|
setStateData(stateData: StateData): Promise<boolean>;
|
|
1147
1149
|
_origBrowserContext(): AllBrowserContext;
|
|
1148
1150
|
}
|
|
@@ -1310,4 +1312,4 @@ declare class LsdBrowserController implements LsdBrowserController$1 {
|
|
|
1310
1312
|
}
|
|
1311
1313
|
declare const controller: LsdBrowserController;
|
|
1312
1314
|
|
|
1313
|
-
export { type AllApiRequestContext, type AllBrowser, type AllBrowserContext, type AllFrame, type AllPage, type AllResponse, type BrowserControllerOptions, type BrowserControllerType, type BrowserCreationMethod, type BrowserManager, CheerioElement, type CheerioNode, CheerioPage, type CookieItem, type GotoOptions, type IframeOption, type InputOptions, type KeyInput, type KeyPressOptions, type LocalStorageItem, type LocalStorageOrigin, type LowerCasePaperFormat, type LsdBrowser, type LsdBrowserContext, type LsdBrowserContextOptions, type LsdBrowserController$1 as LsdBrowserController, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdLaunchOptions, type LsdPage, type MouseClickOptions, type MouseClickType, type NavigationWaitUntil, type PDFMargin, type PDFOptions, type PageEvent, type PageExtInPlaywright, type PageExtInPuppeteer, type PageInfo, type PageOpenType, type PageStatus, type PaperFormat, PlaywrightBrowser, PlaywrightBrowserContext, type PlaywrightBrowserTypes, PlaywrightElement, PlaywrightPage, type
|
|
1315
|
+
export { type AllApiRequestContext, type AllBrowser, type AllBrowserContext, type AllFrame, type AllPage, type AllResponse, type BrowserControllerOptions, type BrowserControllerType, type BrowserCreationMethod, type BrowserManager, CheerioElement, type CheerioNode, CheerioPage, type CookieItem, type GotoOptions, type IframeOption, type InputOptions, type KeyInput, type KeyPressOptions, type LocalStorageItem, type LocalStorageOrigin, type LowerCasePaperFormat, type LsdBrowser, type LsdBrowserContext, type LsdBrowserContextOptions, type LsdBrowserController$1 as LsdBrowserController, type LsdBrowserType, type LsdConnectOptions, type LsdElement, type LsdLaunchOptions, type LsdPage, type MouseClickOptions, type MouseClickType, type NavigationWaitUntil, type PDFMargin, type PDFOptions, type PageEvent, type PageExtInPlaywright, type PageExtInPuppeteer, type PageInfo, type PageOpenType, type PageStatus, type PaperFormat, PlaywrightBrowser, PlaywrightBrowserContext, type PlaywrightBrowserTypes, PlaywrightElement, PlaywrightPage, type ProxyInController, PuppeteerBrowser, PuppeteerBrowserContext, PuppeteerElement, PuppeteerPage, type RequestInterceptionAction, type RequestInterceptionOption, type RequestMatch, type RequestMethod, type RequestResourceType, type ResponseHandler, type ResponseHandlerOptions, type ResponseInterceptionItem, type ResponseInterceptionOption, type ResponseMatch, type ResponsePageData, type ScreenshotOptions, type SelectOptions, type StateData, type UpdatablePageInfo, type ViewportSize, type WaitElementOptions, type WaitElementState, type WaitNavigationOptions, controller };
|
package/dist/index.js
CHANGED
|
@@ -43,16 +43,6 @@ var require_boolbase = __commonJS({
|
|
|
43
43
|
}
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
// src/types/types.ts
|
|
47
|
-
var defaultProxy = {
|
|
48
|
-
server: "default",
|
|
49
|
-
proxyIpType: "residential",
|
|
50
|
-
proxyDurationType: "static",
|
|
51
|
-
proxySharedType: "dedicated",
|
|
52
|
-
expireTime: 41024196e5
|
|
53
|
-
// "2100-01-01 01:00:00"
|
|
54
|
-
};
|
|
55
|
-
|
|
56
46
|
// src/playwright/browser.ts
|
|
57
47
|
import EventEmitter3 from "events";
|
|
58
48
|
|
|
@@ -159,8 +149,8 @@ var PlaywrightElement = class _PlaywrightElement {
|
|
|
159
149
|
}
|
|
160
150
|
try {
|
|
161
151
|
let locators = [];
|
|
162
|
-
if (selector.startsWith("./") || selector.startsWith("/")) {
|
|
163
|
-
locators = await parent2.locator(selector).all();
|
|
152
|
+
if (selector.startsWith("./") || selector.startsWith("/") || selector.startsWith("..")) {
|
|
153
|
+
locators = await parent2.locator(`xpath=${selector}`).all();
|
|
164
154
|
} else {
|
|
165
155
|
if (selector !== ".") {
|
|
166
156
|
locators = await parent2.locator(selector).all();
|
|
@@ -504,8 +494,8 @@ var PlaywrightPage = class extends EventEmitter {
|
|
|
504
494
|
}
|
|
505
495
|
try {
|
|
506
496
|
let locators = [];
|
|
507
|
-
if (selector.startsWith("./") || selector.startsWith("/")) {
|
|
508
|
-
locators = await frame.locator(selector).all();
|
|
497
|
+
if (selector.startsWith("./") || selector.startsWith("/") || selector.startsWith("..")) {
|
|
498
|
+
locators = await frame.locator(`xpath=${selector}`).all();
|
|
509
499
|
} else {
|
|
510
500
|
if (selector !== ".") {
|
|
511
501
|
locators = await frame.locator(selector).all();
|
|
@@ -1214,7 +1204,7 @@ var PlaywrightBrowserContext = class extends EventEmitter2 {
|
|
|
1214
1204
|
this.#browserContext = browserContext;
|
|
1215
1205
|
this.#createTime = getCurrentUnixTime2();
|
|
1216
1206
|
this.#incognito = incognito === false ? false : true;
|
|
1217
|
-
this.#proxy = proxy?.
|
|
1207
|
+
this.#proxy = proxy?.proxyUrl ? proxy : null;
|
|
1218
1208
|
this.#maxPagesPerBrowserContext = maxPagesPerBrowserContext;
|
|
1219
1209
|
this.#maxPageFreeSeconds = maxPageFreeSeconds;
|
|
1220
1210
|
this.#maxViewportOfNewPage = maxViewportOfNewPage;
|
|
@@ -1523,7 +1513,7 @@ var PlaywrightBrowser = class extends EventEmitter3 {
|
|
|
1523
1513
|
}
|
|
1524
1514
|
const proxy = options?.proxy ? Object.assign({}, options.proxy) : this.#proxy;
|
|
1525
1515
|
if (proxy) {
|
|
1526
|
-
const { server, username, password } = proxy;
|
|
1516
|
+
const { proxyUrl: server, username, password } = proxy;
|
|
1527
1517
|
browserContextOptions.proxy = { server, username, password };
|
|
1528
1518
|
}
|
|
1529
1519
|
if (options?.userAgent) {
|
|
@@ -1667,11 +1657,13 @@ var PuppeteerElement = class _PuppeteerElement {
|
|
|
1667
1657
|
return retObj;
|
|
1668
1658
|
}
|
|
1669
1659
|
retObj.frame = frame;
|
|
1660
|
+
absolute = true;
|
|
1670
1661
|
parent2 = frame;
|
|
1671
1662
|
}
|
|
1672
1663
|
try {
|
|
1673
|
-
if (selector.startsWith("./") || selector.startsWith("/")) {
|
|
1674
|
-
|
|
1664
|
+
if (selector.startsWith("./") || selector.startsWith("/") || selector.startsWith("..")) {
|
|
1665
|
+
const newSelector = !absolute && selector.startsWith("/") ? `.${selector}` : selector;
|
|
1666
|
+
retObj.elementHandles = await parent2.$$(`::-p-xpath(${newSelector})`);
|
|
1675
1667
|
} else {
|
|
1676
1668
|
if (selector !== ".") {
|
|
1677
1669
|
retObj.elementHandles = await parent2.$$(selector);
|
|
@@ -1993,8 +1985,8 @@ var PuppeteerPage = class extends EventEmitter4 {
|
|
|
1993
1985
|
retObj.frame = frame;
|
|
1994
1986
|
}
|
|
1995
1987
|
try {
|
|
1996
|
-
if (selector.startsWith("./") || selector.startsWith("/")) {
|
|
1997
|
-
retObj.elementHandles = await frame.$$(selector);
|
|
1988
|
+
if (selector.startsWith("./") || selector.startsWith("/") || selector.startsWith("..")) {
|
|
1989
|
+
retObj.elementHandles = await frame.$$(`::-p-xpath(${selector})`);
|
|
1998
1990
|
} else {
|
|
1999
1991
|
if (selector !== ".") {
|
|
2000
1992
|
retObj.elementHandles = await frame.$$(selector);
|
|
@@ -2697,7 +2689,7 @@ var PuppeteerBrowserContext = class extends EventEmitter5 {
|
|
|
2697
2689
|
this.#userAgent = userAgent;
|
|
2698
2690
|
this.#createTime = getCurrentUnixTime4();
|
|
2699
2691
|
this.#incognito = incognito === false ? false : true;
|
|
2700
|
-
this.#proxy = proxy?.
|
|
2692
|
+
this.#proxy = proxy?.proxyUrl ? proxy : null;
|
|
2701
2693
|
this.#maxPagesPerBrowserContext = maxPagesPerBrowserContext;
|
|
2702
2694
|
this.#maxPageFreeSeconds = maxPageFreeSeconds;
|
|
2703
2695
|
this.#maxViewportOfNewPage = maxViewportOfNewPage;
|
|
@@ -3010,8 +3002,8 @@ var PuppeteerBrowser = class extends EventEmitter6 {
|
|
|
3010
3002
|
}
|
|
3011
3003
|
const browserContextOptions = {};
|
|
3012
3004
|
const proxy = options?.proxy ? Object.assign({}, options.proxy) : this.#proxy;
|
|
3013
|
-
if (proxy?.
|
|
3014
|
-
browserContextOptions.proxyServer = proxy.
|
|
3005
|
+
if (proxy?.proxyUrl) {
|
|
3006
|
+
browserContextOptions.proxyServer = proxy.proxyUrl;
|
|
3015
3007
|
}
|
|
3016
3008
|
const browserContext = await this.#browser.createBrowserContext(browserContextOptions);
|
|
3017
3009
|
const userAgent = options?.userAgent ? options.userAgent : "";
|
|
@@ -17368,8 +17360,9 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17368
17360
|
if (maxWindowSize) {
|
|
17369
17361
|
args.push("--start-maximized");
|
|
17370
17362
|
}
|
|
17371
|
-
if (proxy?.
|
|
17372
|
-
|
|
17363
|
+
if (proxy?.proxyUrl && proxy.proxyUrl !== "local") {
|
|
17364
|
+
const { proxyUrl: server, username, password } = proxy;
|
|
17365
|
+
launchOptions.proxy = { server, username, password };
|
|
17373
17366
|
} else if (proxyPerBrowserContext && browserType === "chromium" && this.#osPlatform.startsWith("win")) {
|
|
17374
17367
|
launchOptions.proxy = { server: "proxyPerBrowserContext" };
|
|
17375
17368
|
}
|
|
@@ -17408,8 +17401,8 @@ var LsdBrowserController = class _LsdBrowserController {
|
|
|
17408
17401
|
} else if (userDataDir) {
|
|
17409
17402
|
args.push(`--user-data-dir=${userDataDir}`);
|
|
17410
17403
|
}
|
|
17411
|
-
if (proxy?.
|
|
17412
|
-
args.push(`--proxy-server=${proxy.
|
|
17404
|
+
if (proxy?.proxyUrl && proxy.proxyUrl !== "default") {
|
|
17405
|
+
args.push(`--proxy-server=${proxy.proxyUrl}`);
|
|
17413
17406
|
} else if (proxyPerBrowserContext && browserType === "chromium" && this.#osPlatform.startsWith("win")) {
|
|
17414
17407
|
args.push(`--proxy-server=proxyPerBrowserContext`);
|
|
17415
17408
|
}
|
|
@@ -17481,6 +17474,5 @@ export {
|
|
|
17481
17474
|
PuppeteerBrowserContext,
|
|
17482
17475
|
PuppeteerElement,
|
|
17483
17476
|
PuppeteerPage,
|
|
17484
|
-
controller
|
|
17485
|
-
defaultProxy
|
|
17477
|
+
controller
|
|
17486
17478
|
};
|
package/package.json
CHANGED