single-file-cli 2.0.48 → 2.0.50

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
  #!/usr/bin/env bash
2
2
 
3
- deno vendor "npm:single-file-core@1.5.12"
3
+ deno vendor "npm:single-file-core@1.5.15"
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.48",
3
+ "version": "2.0.50",
4
4
  "description": "SingleFile CLI",
5
5
  "nodeModulesDir": true,
6
6
  "exports": {
package/lib/cdp-client.js CHANGED
@@ -35,6 +35,7 @@ const EMPTY_PAGE_URL = "about:blank";
35
35
  const CAPTURE_SCREENSHOT_FUNCTION_NAME = "captureScreenshot";
36
36
  const SET_SCREENSHOT_FUNCTION_NAME = "setScreenshot";
37
37
  const SET_PAGE_DATA_FUNCTION_NAME = "setPageData";
38
+ const REDIRECT_STATUS_CODES = [301, 302, 303, 307, 308];
38
39
 
39
40
  export { initialize, getPageData, closeBrowser };
40
41
 
@@ -104,8 +105,10 @@ async function getPageData(options) {
104
105
  await Emulation.setUserAgentOverride(agentOptions);
105
106
  }
106
107
  }
107
- if (options.httpProxyUsername) {
108
- await Fetch.enable({ handleAuthRequests: true });
108
+ const handleAuthRequests = Boolean(options.httpProxyUsername);
109
+ const patterns = handleAuthRequests ? [{ requestStage: "Request" }, { requestStage: "Response" }] : [{ requestStage: "Response" }];
110
+ await Fetch.enable({ handleAuthRequests, patterns });
111
+ if (handleAuthRequests) {
109
112
  Fetch.addEventListener("authRequired", ({ params }) => Fetch.continueWithAuth({
110
113
  requestId: params.requestId,
111
114
  authChallengeResponse: {
@@ -114,8 +117,42 @@ async function getPageData(options) {
114
117
  password: options.httpProxyPassword
115
118
  }
116
119
  }));
117
- Fetch.addEventListener("requestPaused", ({ params }) => Fetch.continueRequest({ requestId: params.requestId }));
118
120
  }
121
+ let url = options.url;
122
+ let alternativeUrl = new URL(url);
123
+ if (!alternativeUrl.pathname.endsWith("/")) {
124
+ alternativeUrl.pathname = alternativeUrl.pathname + "/";
125
+ }
126
+ alternativeUrl = alternativeUrl.href;
127
+ let httpInfo;
128
+ delete options.zipScript;
129
+ Fetch.addEventListener("requestPaused", async ({ params }) => {
130
+ const { requestId, request, resourceType, responseHeaders, responseStatusCode, responseStatusText } = params;
131
+ if (options.outputJson && !httpInfo && (request.url == url || request.url == alternativeUrl) && responseStatusCode !== undefined) {
132
+ if (REDIRECT_STATUS_CODES.includes(responseStatusCode)) {
133
+ const redirect = responseHeaders.find(header => header.name.toLowerCase() == "location").value;
134
+ if (redirect) {
135
+ url = new URL(redirect, url).href;
136
+ }
137
+ } else {
138
+ httpInfo = {
139
+ request: {
140
+ url: request.url,
141
+ method: request.method,
142
+ headers: request.headers,
143
+ referrerPolicy: request.referrerPolicy
144
+ },
145
+ resourceType,
146
+ response: {
147
+ status: responseStatusCode,
148
+ statusText: responseStatusText,
149
+ headers: responseHeaders
150
+ }
151
+ };
152
+ }
153
+ }
154
+ await Fetch.continueRequest({ requestId });
155
+ });
119
156
  if (options.httpHeaders && options.httpHeaders.length) {
120
157
  await Network.setExtraHTTPHeaders({ headers: options.httpHeaders });
121
158
  }
@@ -182,7 +219,9 @@ async function getPageData(options) {
182
219
  if (subtype === "error") {
183
220
  throw new Error(description);
184
221
  }
185
- return pageDataPromise;
222
+ const pageData = await pageDataPromise;
223
+ Object.assign(pageData, httpInfo);
224
+ return pageData;
186
225
  } catch (error) {
187
226
  if (error.code === LOAD_TIMEOUT_ERROR && options.browserWaitUntilFallback && options.browserWaitUntil) {
188
227
  const browserWaitUntil = NETWORK_STATES[(NETWORK_STATES.indexOf(options.browserWaitUntil) + 1)];