single-file-cli 2.0.47 → 2.0.49
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 +43 -4
- package/lib/single-file-bundle.js +1 -1
- package/lib/version.js +1 -1
- package/options.js +2 -1
- package/package.json +1 -1
- package/single-file-cli-api.js +28 -9
package/build.sh
CHANGED
package/deno.json
CHANGED
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
|
-
|
|
108
|
-
|
|
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
|
-
|
|
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)];
|