single-file-cli 2.0.38 → 2.0.40
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/build.sh +1 -1
- package/deno.json +1 -1
- package/lib/cdp-client.js +42 -4
- package/lib/single-file-bundle.js +1 -1
- package/lib/version.js +1 -1
- package/options.js +6 -0
- package/package.json +1 -1
- package/single-file-cli-api.js +1 -1
package/build.sh
CHANGED
package/deno.json
CHANGED
package/lib/cdp-client.js
CHANGED
|
@@ -39,8 +39,8 @@ const SET_PAGE_DATA_FUNCTION_NAME = "setPageData";
|
|
|
39
39
|
export { initialize, getPageData, closeBrowser };
|
|
40
40
|
|
|
41
41
|
async function initialize(singleFileOptions) {
|
|
42
|
-
if (
|
|
43
|
-
options.apiUrl = singleFileOptions.
|
|
42
|
+
if (singleFileOptions.browserServer) {
|
|
43
|
+
options.apiUrl = singleFileOptions.browserServer;
|
|
44
44
|
} else {
|
|
45
45
|
options.apiUrl = "http://localhost:" + (await launchBrowser(getBrowserOptions(singleFileOptions)));
|
|
46
46
|
}
|
|
@@ -63,8 +63,46 @@ async function getPageData(options) {
|
|
|
63
63
|
if (options.browserByPassCSP === undefined || options.browserByPassCSP) {
|
|
64
64
|
await Page.setBypassCSP({ enabled: true });
|
|
65
65
|
}
|
|
66
|
-
if (options.browserMobileEmulation) {
|
|
67
|
-
|
|
66
|
+
if (options.browserMobileEmulation || options.browserDeviceWidth || options.browserDeviceHeight || options.browserDeviceScaleFactor || options.platform || options.acceptLanguage) {
|
|
67
|
+
if (options.browserMobileEmulation || options.browserDeviceWidth || options.browserDeviceHeight || options.browserDeviceScaleFactor) {
|
|
68
|
+
let browserDeviceWidth;
|
|
69
|
+
if (!options.browserDeviceWidth) {
|
|
70
|
+
const { result } = await Runtime.evaluate({ expression: "window.innerWidth" });
|
|
71
|
+
browserDeviceWidth = result.value;
|
|
72
|
+
}
|
|
73
|
+
let browserDeviceHeight;
|
|
74
|
+
if (!options.browserDeviceHeight) {
|
|
75
|
+
const { result } = await Runtime.evaluate({ expression: "window.innerHeight" });
|
|
76
|
+
browserDeviceHeight = result.value;
|
|
77
|
+
}
|
|
78
|
+
let browserDeviceScaleFactor;
|
|
79
|
+
if (!options.browserDeviceScaleFactor) {
|
|
80
|
+
const { result } = await Runtime.evaluate({ expression: "window.devicePixelRatio" });
|
|
81
|
+
browserDeviceScaleFactor = result.value;
|
|
82
|
+
}
|
|
83
|
+
await Emulation.setDeviceMetricsOverride({
|
|
84
|
+
mobile: Boolean(options.browserMobileEmulation),
|
|
85
|
+
width: options.browserDeviceWidth || (options.browserMobileEmulation ? 360 : options.width || browserDeviceWidth),
|
|
86
|
+
height: options.browserDeviceHeight || (options.browserMobileEmulation ? 800 : options.height || browserDeviceHeight),
|
|
87
|
+
deviceScaleFactor: options.browserDeviceScaleFactor || (options.browserMobileEmulation ? 2 : browserDeviceScaleFactor)
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
if (options.browserMobileEmulation || options.platform || options.acceptLanguage) {
|
|
91
|
+
let browserUserAgent;
|
|
92
|
+
if (!options.userAgent) {
|
|
93
|
+
({ browserUserAgent } = await Browser.getVersion());
|
|
94
|
+
}
|
|
95
|
+
const options = {
|
|
96
|
+
userAgent: options.userAgent || (options.browserMobileEmulation ? "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome Mobile Safari/537.36" : browserUserAgent)
|
|
97
|
+
};
|
|
98
|
+
if (options.acceptLanguage) {
|
|
99
|
+
options.acceptLanguage = options.acceptLanguage;
|
|
100
|
+
}
|
|
101
|
+
if (options.platform || options.browserMobileEmulation) {
|
|
102
|
+
options.platform = options.platform || "Android";
|
|
103
|
+
}
|
|
104
|
+
await Emulation.setUserAgentOverride(options);
|
|
105
|
+
}
|
|
68
106
|
}
|
|
69
107
|
if (options.httpProxyUsername) {
|
|
70
108
|
await Fetch.enable({ handleAuthRequests: true });
|