single-file-cli 2.0.38 → 2.0.41

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/bin/sh
2
2
 
3
- deno vendor "npm:single-file-core@1.4.5"
3
+ deno vendor "npm:single-file-core@1.4.7"
4
4
 
5
5
  echo "
6
6
  import { build } from 'npm:esbuild';
package/deno.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@single-file/single-file-cli",
3
- "version": "2.0.38",
3
+ "version": "2.0.41",
4
4
  "description": "SingleFile CLI",
5
5
  "nodeModulesDir": true,
6
6
  "exports": {
package/lib/browser.js CHANGED
@@ -117,7 +117,11 @@ async function closeBrowser() {
117
117
  child = undefined;
118
118
  }
119
119
  if (profilePath !== undefined) {
120
- await remove(profilePath, { recursive: true });
121
- profilePath = undefined;
120
+ try {
121
+ await remove(profilePath, { recursive: true });
122
+ profilePath = undefined;
123
+ } catch (error) {
124
+ console.log("Warning: failed to remove profile directory: " + error.message); // eslint-disable-line no-console
125
+ }
122
126
  }
123
127
  }
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 (options.browserRemoteDebuggingURL) {
43
- options.apiUrl = singleFileOptions.browserRemoteDebuggingURL;
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
- await Emulation.setDeviceMetricsOverride({ mobile: true });
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 agentOptions = {
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
+ agentOptions.acceptLanguage = options.acceptLanguage;
100
+ }
101
+ if (options.platform || options.browserMobileEmulation) {
102
+ agentOptions.platform = options.platform || "Android";
103
+ }
104
+ await Emulation.setUserAgentOverride(agentOptions);
105
+ }
68
106
  }
69
107
  if (options.httpProxyUsername) {
70
108
  await Fetch.enable({ handleAuthRequests: true });
@@ -359,4 +397,4 @@ function getBrowserOptions(options) {
359
397
  browserOptions.userAgent = options.userAgent;
360
398
  browserOptions.httpProxyServer = options.httpProxyServer;
361
399
  return browserOptions;
362
- }
400
+ }