@google-psat/analysis-utils 0.14.1 → 1.0.0-1
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/browserManagement/collateCookieData.js +1 -4
- package/dist/browserManagement/collateCookieData.js.map +1 -1
- package/dist/browserManagement/index.js +377 -490
- package/dist/browserManagement/index.js.map +1 -1
- package/dist/browserManagement/parseNetworkDataToCookieData.js +44 -38
- package/dist/browserManagement/parseNetworkDataToCookieData.js.map +1 -1
- package/dist/browserManagement/types.js +1 -2
- package/dist/constants.js +2 -5
- package/dist/constants.js.map +1 -1
- package/dist/index.js +1 -17
- package/dist/index.js.map +1 -1
- package/dist/procedures/analyzeCookiesUrlsAndFetchResources.js +15 -29
- package/dist/procedures/analyzeCookiesUrlsAndFetchResources.js.map +1 -1
- package/dist/procedures/analyzeCookiesUrlsInBatchesAndFetchResources.js +6 -19
- package/dist/procedures/analyzeCookiesUrlsInBatchesAndFetchResources.js.map +1 -1
- package/dist/procedures/index.js +2 -7
- package/dist/procedures/index.js.map +1 -1
- package/dist/types.js +1 -2
- package/dist-types/browserManagement/index.d.ts +3 -11
- package/dist-types/procedures/analyzeCookiesUrlsAndFetchResources.d.ts +2 -3
- package/dist-types/procedures/analyzeCookiesUrlsInBatchesAndFetchResources.d.ts +2 -3
- package/package.json +1 -7
- package/tsconfig.json +3 -3
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*
|
|
3
2
|
* Copyright 2023 Google LLC
|
|
4
3
|
*
|
|
@@ -14,32 +13,31 @@
|
|
|
14
13
|
* See the License for the specific language governing permissions and
|
|
15
14
|
* limitations under the License.
|
|
16
15
|
*/
|
|
17
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.BrowserManagement = void 0;
|
|
31
16
|
/**
|
|
32
17
|
* External dependencies.
|
|
33
18
|
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class BrowserManagement {
|
|
19
|
+
import puppeteer from 'puppeteer';
|
|
20
|
+
import { parse } from 'simple-cookie';
|
|
21
|
+
import { resolveWithTimeout, delay, RESPONSE_EVENT, REQUEST_EVENT, } from '@google-psat/common';
|
|
22
|
+
import { parseNetworkDataToCookieData } from './parseNetworkDataToCookieData';
|
|
23
|
+
import collateCookieData from './collateCookieData';
|
|
24
|
+
import { CMP_SELECTORS, CMP_TEXT_SELECTORS } from '../constants';
|
|
25
|
+
export class BrowserManagement {
|
|
26
|
+
viewportConfig;
|
|
27
|
+
browser;
|
|
28
|
+
isHeadless;
|
|
29
|
+
pageWaitTime;
|
|
30
|
+
pages;
|
|
31
|
+
erroredOutUrls;
|
|
32
|
+
pageFrames;
|
|
33
|
+
pageResponses;
|
|
34
|
+
pageRequests;
|
|
35
|
+
shouldLogDebug;
|
|
36
|
+
spinnies;
|
|
37
|
+
isSiteMap;
|
|
38
|
+
indent = 0;
|
|
39
|
+
selectors;
|
|
41
40
|
constructor(viewportConfig, isHeadless, pageWaitTime, shouldLogDebug, indent, isSiteMap, spinnies, selectors) {
|
|
42
|
-
this.indent = 0;
|
|
43
41
|
this.viewportConfig = viewportConfig;
|
|
44
42
|
this.browser = null;
|
|
45
43
|
this.isHeadless = isHeadless;
|
|
@@ -50,7 +48,6 @@ class BrowserManagement {
|
|
|
50
48
|
this.pageResponses = {};
|
|
51
49
|
this.pageRequests = {};
|
|
52
50
|
this.shouldLogDebug = shouldLogDebug;
|
|
53
|
-
this.pageResourcesMaps = {};
|
|
54
51
|
this.spinnies = spinnies;
|
|
55
52
|
this.indent = indent;
|
|
56
53
|
this.erroredOutUrls = {};
|
|
@@ -68,169 +65,155 @@ class BrowserManagement {
|
|
|
68
65
|
});
|
|
69
66
|
}
|
|
70
67
|
}
|
|
71
|
-
initializeBrowser(enable3pCookiePhaseout) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
args,
|
|
82
|
-
});
|
|
83
|
-
this.debugLog('Browser initialized');
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
clickOnButtonUsingCMPSelectors(page) {
|
|
87
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
let clickedOnButton = false;
|
|
89
|
-
yield Promise.all(constants_1.CMP_SELECTORS.map((selector) => __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
const buttonToClick = yield page.$(selector);
|
|
91
|
-
if (buttonToClick) {
|
|
92
|
-
yield buttonToClick.click();
|
|
93
|
-
clickedOnButton = true;
|
|
94
|
-
}
|
|
95
|
-
})));
|
|
96
|
-
return clickedOnButton;
|
|
68
|
+
async initializeBrowser(enable3pCookiePhaseout) {
|
|
69
|
+
const args = [];
|
|
70
|
+
if (enable3pCookiePhaseout) {
|
|
71
|
+
args.push('--test-third-party-cookie-phaseout');
|
|
72
|
+
args.push('--enable-features="FirstPartySets,StorageAccessAPI,StorageAccessAPIForOriginExtension,PageInfoCookiesSubpage,PrivacySandboxFirstPartySetsUI,TpcdMetadataGrants,TpcdSupportSettings,TpcdHeuristicsGrants:TpcdReadHeuristicsGrants/true/TpcdWritePopupCurrentInteractionHeuristicsGrants/30d/TpcdBackfillPopupHeuristicsGrants/30d/TpcdPopupHeuristicEnableForIframeInitiator/all/TpcdWriteRedirectHeuristicGrants/15m/TpcdRedirectHeuristicRequireABAFlow/true/TpcdRedirectHeuristicRequireCurrentInteraction/true"');
|
|
73
|
+
}
|
|
74
|
+
this.browser = await puppeteer.launch({
|
|
75
|
+
devtools: true,
|
|
76
|
+
headless: this.isHeadless,
|
|
77
|
+
args,
|
|
97
78
|
});
|
|
79
|
+
this.debugLog('Browser initialized');
|
|
98
80
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
81
|
+
async clickOnButtonUsingCMPSelectors(page) {
|
|
82
|
+
let clickedOnButton = false;
|
|
83
|
+
await Promise.all(CMP_SELECTORS.map(async (selector) => {
|
|
84
|
+
const buttonToClick = await page.$(selector);
|
|
85
|
+
if (buttonToClick) {
|
|
86
|
+
await buttonToClick.click();
|
|
87
|
+
clickedOnButton = true;
|
|
103
88
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
89
|
+
}));
|
|
90
|
+
return clickedOnButton;
|
|
91
|
+
}
|
|
92
|
+
async clickOnGDPRUsingTextSelectors(page, textSelectors) {
|
|
93
|
+
if (textSelectors.length === 0) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
const result = await page.evaluate((args) => {
|
|
97
|
+
const bannerNodes = Array.from((document.querySelector('body')?.childNodes || []))
|
|
98
|
+
?.filter((node) => node && node?.tagName === 'DIV')
|
|
99
|
+
?.filter((node) => {
|
|
100
|
+
if (!node || !node?.textContent) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
const regex = /\b(consent|policy|cookie policy|privacy policy|personalize|preferences|cookies)\b/;
|
|
104
|
+
return regex.test(node.textContent.toLowerCase());
|
|
105
|
+
});
|
|
106
|
+
return bannerNodes?.some((node) => {
|
|
107
|
+
const buttonNodes = Array.from(node?.getElementsByTagName('button'));
|
|
108
|
+
return buttonNodes?.some((cnode) => {
|
|
109
|
+
if (!cnode?.textContent) {
|
|
108
110
|
return false;
|
|
109
111
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const buttonNodes = Array.from(node === null || node === void 0 ? void 0 : node.getElementsByTagName('button'));
|
|
115
|
-
return buttonNodes === null || buttonNodes === void 0 ? void 0 : buttonNodes.some((cnode) => {
|
|
116
|
-
if (!(cnode === null || cnode === void 0 ? void 0 : cnode.textContent)) {
|
|
117
|
-
return false;
|
|
112
|
+
return args.some((text) => {
|
|
113
|
+
if (cnode?.textContent?.toLowerCase().includes(text)) {
|
|
114
|
+
cnode?.click();
|
|
115
|
+
return true;
|
|
118
116
|
}
|
|
119
|
-
return
|
|
120
|
-
var _a;
|
|
121
|
-
if ((_a = cnode === null || cnode === void 0 ? void 0 : cnode.textContent) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes(text)) {
|
|
122
|
-
cnode === null || cnode === void 0 ? void 0 : cnode.click();
|
|
123
|
-
return true;
|
|
124
|
-
}
|
|
125
|
-
return false;
|
|
126
|
-
});
|
|
117
|
+
return false;
|
|
127
118
|
});
|
|
128
119
|
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
|
|
120
|
+
});
|
|
121
|
+
}, textSelectors);
|
|
122
|
+
return result;
|
|
132
123
|
}
|
|
133
|
-
clickOnAcceptBanner(url) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
this.debugLog('GDPR banner found and accepted');
|
|
144
|
-
yield (0, common_1.delay)(this.pageWaitTime / 2);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
// Click using CSS selectors.
|
|
148
|
-
const clickedUsingCMPCSSSelectors = yield this.clickOnButtonUsingCMPSelectors(page);
|
|
149
|
-
if (clickedUsingCMPCSSSelectors) {
|
|
150
|
-
this.debugLog('GDPR banner found and accepted');
|
|
151
|
-
yield (0, common_1.delay)(this.pageWaitTime / 2);
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
const buttonClicked = yield this.clickOnGDPRUsingTextSelectors(page, constants_1.CMP_TEXT_SELECTORS);
|
|
155
|
-
if (buttonClicked) {
|
|
156
|
-
this.debugLog('GDPR banner found and accepted');
|
|
157
|
-
yield (0, common_1.delay)(this.pageWaitTime / 2);
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
this.debugLog('GDPR banner could not be found');
|
|
161
|
-
yield (0, common_1.delay)(this.pageWaitTime / 2);
|
|
124
|
+
async clickOnAcceptBanner(url) {
|
|
125
|
+
try {
|
|
126
|
+
const page = this.pages[url];
|
|
127
|
+
if (!page) {
|
|
128
|
+
throw new Error('No page with the provided id was found');
|
|
129
|
+
}
|
|
130
|
+
const didSelectorsFromUserWork = await this.useSelectorsToSelectGDPRBanner(page);
|
|
131
|
+
if (didSelectorsFromUserWork) {
|
|
132
|
+
this.debugLog('GDPR banner found and accepted');
|
|
133
|
+
await delay(this.pageWaitTime / 2);
|
|
162
134
|
return;
|
|
163
135
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
});
|
|
171
|
-
}
|
|
136
|
+
// Click using CSS selectors.
|
|
137
|
+
const clickedUsingCMPCSSSelectors = await this.clickOnButtonUsingCMPSelectors(page);
|
|
138
|
+
if (clickedUsingCMPCSSSelectors) {
|
|
139
|
+
this.debugLog('GDPR banner found and accepted');
|
|
140
|
+
await delay(this.pageWaitTime / 2);
|
|
141
|
+
return;
|
|
172
142
|
}
|
|
173
|
-
|
|
143
|
+
const buttonClicked = await this.clickOnGDPRUsingTextSelectors(page, CMP_TEXT_SELECTORS);
|
|
144
|
+
if (buttonClicked) {
|
|
145
|
+
this.debugLog('GDPR banner found and accepted');
|
|
146
|
+
await delay(this.pageWaitTime / 2);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
this.debugLog('GDPR banner could not be found');
|
|
150
|
+
await delay(this.pageWaitTime / 2);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
if (error instanceof Error) {
|
|
155
|
+
this.pushErrors(url, {
|
|
156
|
+
errorMessage: error.message,
|
|
157
|
+
stackTrace: error?.stack ?? '',
|
|
158
|
+
errorName: error?.name,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
174
162
|
}
|
|
175
|
-
useSelectorsToSelectGDPRBanner(page) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
163
|
+
async useSelectorsToSelectGDPRBanner(page) {
|
|
164
|
+
let clickedOnButton = false;
|
|
165
|
+
if (!this.selectors) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
await Promise.all(this.selectors?.cssSelectors.map(async (selector) => {
|
|
169
|
+
const buttonToClick = await page.$(selector);
|
|
170
|
+
if (buttonToClick) {
|
|
171
|
+
clickedOnButton = true;
|
|
172
|
+
this.debugLog('GDPR banner found and accepted');
|
|
173
|
+
await buttonToClick.click();
|
|
181
174
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
if (clickedOnButton) {
|
|
191
|
-
return clickedOnButton;
|
|
175
|
+
}));
|
|
176
|
+
if (clickedOnButton) {
|
|
177
|
+
return clickedOnButton;
|
|
178
|
+
}
|
|
179
|
+
clickedOnButton = await page.evaluate((xPaths) => {
|
|
180
|
+
const rootElement = document.querySelector('html');
|
|
181
|
+
if (!rootElement) {
|
|
182
|
+
return false;
|
|
192
183
|
}
|
|
193
|
-
|
|
194
|
-
const
|
|
195
|
-
|
|
184
|
+
return xPaths.some((xPath) => {
|
|
185
|
+
const _acceptButton = document
|
|
186
|
+
.evaluate(xPath, rootElement)
|
|
187
|
+
.iterateNext();
|
|
188
|
+
if (!_acceptButton) {
|
|
196
189
|
return false;
|
|
197
190
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
_acceptButton === null || _acceptButton === void 0 ? void 0 : _acceptButton.click();
|
|
207
|
-
return true;
|
|
208
|
-
}
|
|
209
|
-
return false;
|
|
210
|
-
});
|
|
211
|
-
}, (_b = this.selectors) === null || _b === void 0 ? void 0 : _b.xPath);
|
|
212
|
-
if (clickedOnButton) {
|
|
213
|
-
return clickedOnButton;
|
|
214
|
-
}
|
|
215
|
-
clickedOnButton = yield this.clickOnGDPRUsingTextSelectors(page, (_c = this.selectors) === null || _c === void 0 ? void 0 : _c.textSelectors);
|
|
191
|
+
if (_acceptButton instanceof HTMLElement) {
|
|
192
|
+
_acceptButton?.click();
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
return false;
|
|
196
|
+
});
|
|
197
|
+
}, this.selectors?.xPath);
|
|
198
|
+
if (clickedOnButton) {
|
|
216
199
|
return clickedOnButton;
|
|
217
|
-
}
|
|
200
|
+
}
|
|
201
|
+
clickedOnButton = await this.clickOnGDPRUsingTextSelectors(page, this.selectors?.textSelectors);
|
|
202
|
+
return clickedOnButton;
|
|
218
203
|
}
|
|
219
|
-
openPage() {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
deviceScaleFactor: 1,
|
|
230
|
-
});
|
|
231
|
-
this.debugLog('Page opened');
|
|
232
|
-
return sitePage;
|
|
204
|
+
async openPage() {
|
|
205
|
+
if (!this.browser) {
|
|
206
|
+
throw new Error('Browser not initialized');
|
|
207
|
+
}
|
|
208
|
+
const sitePage = await this.browser.newPage();
|
|
209
|
+
await sitePage.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36');
|
|
210
|
+
sitePage.setViewport({
|
|
211
|
+
width: 1440,
|
|
212
|
+
height: 790,
|
|
213
|
+
deviceScaleFactor: 1,
|
|
233
214
|
});
|
|
215
|
+
this.debugLog('Page opened');
|
|
216
|
+
return sitePage;
|
|
234
217
|
}
|
|
235
218
|
pushErrors(url, objectToPushed) {
|
|
236
219
|
if (!this.erroredOutUrls[url]) {
|
|
@@ -238,86 +221,61 @@ class BrowserManagement {
|
|
|
238
221
|
}
|
|
239
222
|
this.erroredOutUrls[url].push(objectToPushed);
|
|
240
223
|
}
|
|
241
|
-
navigateToPage(url) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
224
|
+
async navigateToPage(url) {
|
|
225
|
+
const page = this.pages[url];
|
|
226
|
+
if (!page) {
|
|
227
|
+
throw new Error('No page with the provided ID was found');
|
|
228
|
+
}
|
|
229
|
+
this.debugLog(`Starting navigation to URL: ${url}`);
|
|
230
|
+
try {
|
|
231
|
+
const response = await page.goto(url, {
|
|
232
|
+
timeout: 10000,
|
|
233
|
+
});
|
|
234
|
+
const SUCCESS_RESPONSE = 200;
|
|
235
|
+
if (response && response.status() !== SUCCESS_RESPONSE) {
|
|
236
|
+
this.pushErrors(url, {
|
|
237
|
+
errorMessage: `Invalid server response: ${response.status()}`,
|
|
238
|
+
errorCode: `${response.status()}`,
|
|
239
|
+
errorName: `INVALID_SERVER_RESPONSE`,
|
|
252
240
|
});
|
|
253
|
-
|
|
254
|
-
if (
|
|
255
|
-
|
|
256
|
-
errorMessage: `Invalid server response: ${response.status()}`,
|
|
257
|
-
errorCode: `${response.status()}`,
|
|
258
|
-
errorName: `INVALID_SERVER_RESPONSE`,
|
|
259
|
-
});
|
|
260
|
-
this.debugLog(`Warning: Server error found in URL: ${url}`, true);
|
|
261
|
-
if (!this.isSiteMap) {
|
|
262
|
-
throw new Error(`Invalid server response: ${response.status()}`);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
this.debugLog(`Navigation completed to URL: ${url}`);
|
|
266
|
-
}
|
|
267
|
-
catch (error) {
|
|
268
|
-
if (error instanceof Error) {
|
|
269
|
-
this.pushErrors(url, {
|
|
270
|
-
errorMessage: error.message,
|
|
271
|
-
stackTrace: (_a = error === null || error === void 0 ? void 0 : error.stack) !== null && _a !== void 0 ? _a : '',
|
|
272
|
-
errorName: error === null || error === void 0 ? void 0 : error.name,
|
|
273
|
-
});
|
|
274
|
-
if ((error === null || error === void 0 ? void 0 : error.name) === 'TimeoutError' || (error === null || error === void 0 ? void 0 : error.name) === 'i') {
|
|
275
|
-
this.debugLog(`Navigation did not finish on URL ${url} in 10 seconds moving on to scrolling`);
|
|
276
|
-
}
|
|
277
|
-
throw error;
|
|
241
|
+
this.debugLog(`Warning: Server error found in URL: ${url}`, true);
|
|
242
|
+
if (!this.isSiteMap) {
|
|
243
|
+
throw new Error(`Invalid server response: ${response.status()}`);
|
|
278
244
|
}
|
|
279
245
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
try {
|
|
289
|
-
yield page.evaluate(() => {
|
|
290
|
-
window.scrollBy(0, 10000);
|
|
246
|
+
this.debugLog(`Navigation completed to URL: ${url}`);
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
if (error instanceof Error) {
|
|
250
|
+
this.pushErrors(url, {
|
|
251
|
+
errorMessage: error.message,
|
|
252
|
+
stackTrace: error?.stack ?? '',
|
|
253
|
+
errorName: error?.name,
|
|
291
254
|
});
|
|
255
|
+
if (error?.name === 'TimeoutError' || error?.name === 'i') {
|
|
256
|
+
this.debugLog(`Navigation did not finish on URL ${url} in 10 seconds moving on to scrolling`);
|
|
257
|
+
}
|
|
258
|
+
throw error;
|
|
292
259
|
}
|
|
293
|
-
|
|
294
|
-
this.debugLog('Scrolled to the end of page');
|
|
295
|
-
//ignore
|
|
296
|
-
}
|
|
297
|
-
this.debugLog(`Scrolling on URL: ${url}`);
|
|
298
|
-
});
|
|
260
|
+
}
|
|
299
261
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
if (
|
|
303
|
-
|
|
304
|
-
response
|
|
305
|
-
.text()
|
|
306
|
-
.then((content) => {
|
|
307
|
-
var _a, _b;
|
|
308
|
-
this.pageResourcesMaps[pageId][response.url()] = {
|
|
309
|
-
origin: response.url(),
|
|
310
|
-
type: ((_b = (_a = response === null || response === void 0 ? void 0 : response.headers()) === null || _a === void 0 ? void 0 : _a['content-type']) === null || _b === void 0 ? void 0 : _b.includes('javascript'))
|
|
311
|
-
? 'Script'
|
|
312
|
-
: 'Document',
|
|
313
|
-
content,
|
|
314
|
-
};
|
|
315
|
-
})
|
|
316
|
-
.catch(() => undefined);
|
|
262
|
+
async pageScroll(url) {
|
|
263
|
+
const page = this.pages[url];
|
|
264
|
+
if (!page) {
|
|
265
|
+
throw new Error('No page with the provided ID was found');
|
|
317
266
|
}
|
|
267
|
+
try {
|
|
268
|
+
await page.evaluate(() => {
|
|
269
|
+
window.scrollBy(0, 10000);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
catch (error) {
|
|
273
|
+
this.debugLog('Scrolled to the end of page');
|
|
274
|
+
//ignore
|
|
275
|
+
}
|
|
276
|
+
this.debugLog(`Scrolling on URL: ${url}`);
|
|
318
277
|
}
|
|
319
278
|
responseReceivedListener(pageId, { requestId, frameId, response }) {
|
|
320
|
-
var _a, _b;
|
|
321
279
|
if (!this.pageResponses[pageId][requestId]) {
|
|
322
280
|
this.pageResponses[pageId][requestId] = {
|
|
323
281
|
frameId,
|
|
@@ -326,7 +284,7 @@ class BrowserManagement {
|
|
|
326
284
|
};
|
|
327
285
|
}
|
|
328
286
|
else {
|
|
329
|
-
const parsedCookies =
|
|
287
|
+
const parsedCookies = this.pageResponses[pageId][requestId]?.cookies.map((cookie) => {
|
|
330
288
|
if (!cookie.url) {
|
|
331
289
|
cookie.url = response.url;
|
|
332
290
|
}
|
|
@@ -338,9 +296,8 @@ class BrowserManagement {
|
|
|
338
296
|
}
|
|
339
297
|
return cookie;
|
|
340
298
|
});
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
(_a = cookie.networkEvents) === null || _a === void 0 ? void 0 : _a.responseEvents.map((event) => {
|
|
299
|
+
this.pageResponses[pageId][requestId]?.cookies.forEach((cookie) => {
|
|
300
|
+
cookie.networkEvents?.responseEvents.map((event) => {
|
|
344
301
|
if (event.requestId === requestId) {
|
|
345
302
|
event.url = response.url;
|
|
346
303
|
}
|
|
@@ -355,40 +312,37 @@ class BrowserManagement {
|
|
|
355
312
|
}
|
|
356
313
|
}
|
|
357
314
|
responseReceivedExtraInfoListener(pageId, { headers, cookiePartitionKey, blockedCookies, requestId, exemptedCookies, }) {
|
|
358
|
-
|
|
359
|
-
const headersToBeParsed = (_a = headers['set-cookie']) !== null && _a !== void 0 ? _a : headers['Set-Cookie'];
|
|
315
|
+
const headersToBeParsed = headers['set-cookie'] ?? headers['Set-Cookie'];
|
|
360
316
|
if (!headersToBeParsed) {
|
|
361
317
|
return;
|
|
362
318
|
}
|
|
363
319
|
const cookies = headersToBeParsed
|
|
364
320
|
.split('\n')
|
|
365
321
|
.map((headerLine) => {
|
|
366
|
-
|
|
367
|
-
const
|
|
368
|
-
const url = (_a = this.pageResponses[pageId][requestId]) === null || _a === void 0 ? void 0 : _a.url;
|
|
322
|
+
const parsedCookie = parse(headerLine);
|
|
323
|
+
const url = this.pageResponses[pageId][requestId]?.url;
|
|
369
324
|
if (!parsedCookie.domain && url) {
|
|
370
325
|
parsedCookie.domain = new URL(url).hostname;
|
|
371
326
|
}
|
|
372
327
|
if (parsedCookie.domain && parsedCookie.domain[0] !== '.') {
|
|
373
328
|
parsedCookie.domain = '.' + parsedCookie.domain;
|
|
374
329
|
}
|
|
375
|
-
const exemptedEntry = exemptedCookies
|
|
376
|
-
return
|
|
330
|
+
const exemptedEntry = exemptedCookies?.find(({ cookie }) => {
|
|
331
|
+
return cookie?.name === parsedCookie.name;
|
|
377
332
|
});
|
|
378
333
|
const blockedEntry = blockedCookies.find((c) => {
|
|
379
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
380
334
|
if (c.cookie) {
|
|
381
|
-
return (
|
|
382
|
-
|
|
383
|
-
|
|
335
|
+
return (c.cookie?.name?.trim() === parsedCookie.name?.trim() &&
|
|
336
|
+
c.cookie.domain?.trim() === parsedCookie.domain?.trim() &&
|
|
337
|
+
c.cookie.path?.trim() === parsedCookie.path?.trim());
|
|
384
338
|
}
|
|
385
339
|
else {
|
|
386
|
-
const temporaryParsedCookie =
|
|
387
|
-
return (
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
340
|
+
const temporaryParsedCookie = parse(c.cookieLine);
|
|
341
|
+
return (temporaryParsedCookie.name?.trim() ===
|
|
342
|
+
parsedCookie.name?.trim() &&
|
|
343
|
+
temporaryParsedCookie.domain?.trim() ===
|
|
344
|
+
parsedCookie.domain?.trim() &&
|
|
345
|
+
temporaryParsedCookie.path?.trim() === parsedCookie.path?.trim());
|
|
392
346
|
}
|
|
393
347
|
});
|
|
394
348
|
const singleCookie = {
|
|
@@ -397,7 +351,7 @@ class BrowserManagement {
|
|
|
397
351
|
domain: parsedCookie.domain,
|
|
398
352
|
path: parsedCookie.path || '/',
|
|
399
353
|
value: parsedCookie.value,
|
|
400
|
-
samesite:
|
|
354
|
+
samesite: parsedCookie.samesite?.toLowerCase() || 'lax',
|
|
401
355
|
expires: parsedCookie.expires || 'Session',
|
|
402
356
|
httponly: parsedCookie.httponly || false,
|
|
403
357
|
secure: parsedCookie.secure || false,
|
|
@@ -406,7 +360,7 @@ class BrowserManagement {
|
|
|
406
360
|
networkEvents: {
|
|
407
361
|
responseEvents: [
|
|
408
362
|
{
|
|
409
|
-
type:
|
|
363
|
+
type: RESPONSE_EVENT.CDP_RESPONSE_RECEIVED_EXTRA_INFO,
|
|
410
364
|
requestId,
|
|
411
365
|
url,
|
|
412
366
|
blocked: Boolean(blockedEntry),
|
|
@@ -416,42 +370,45 @@ class BrowserManagement {
|
|
|
416
370
|
requestEvents: [],
|
|
417
371
|
},
|
|
418
372
|
isBlocked: Boolean(blockedEntry),
|
|
419
|
-
blockedReasons: blockedEntry
|
|
420
|
-
exemptionReason: exemptedEntry
|
|
373
|
+
blockedReasons: blockedEntry?.blockedReasons,
|
|
374
|
+
exemptionReason: exemptedEntry?.exemptionReason,
|
|
421
375
|
url,
|
|
422
376
|
headerType: 'response',
|
|
423
377
|
};
|
|
424
378
|
if (headerLine.includes('Partitioned')) {
|
|
425
379
|
singleCookie.parsedCookie.partitionKey =
|
|
426
|
-
cookiePartitionKey
|
|
380
|
+
cookiePartitionKey?.topLevelSite;
|
|
427
381
|
}
|
|
428
382
|
return singleCookie;
|
|
429
383
|
});
|
|
430
|
-
const prevCookies =
|
|
384
|
+
const prevCookies = this.pageResponses[pageId][requestId]?.cookies || [];
|
|
431
385
|
const mergedCookies = [...prevCookies, ...(cookies || [])];
|
|
432
386
|
this.pageResponses[pageId][requestId] = {
|
|
433
|
-
frameId:
|
|
434
|
-
url:
|
|
387
|
+
frameId: this.pageResponses[pageId][requestId]?.frameId || '',
|
|
388
|
+
url: this.pageResponses[pageId][requestId]?.url || '',
|
|
435
389
|
// @ts-ignore TODO: fix expires type mismatch
|
|
436
390
|
cookies: mergedCookies,
|
|
437
391
|
};
|
|
438
392
|
}
|
|
439
393
|
requestWillBeSentListener(pageId, { requestId, request, frameId }) {
|
|
440
|
-
this.pageRequests[pageId][requestId] =
|
|
394
|
+
this.pageRequests[pageId][requestId] = {
|
|
395
|
+
...(this.pageRequests[pageId][requestId] || {}),
|
|
396
|
+
frameId,
|
|
397
|
+
url: request.url,
|
|
398
|
+
};
|
|
441
399
|
}
|
|
442
400
|
requestWillBeSentExtraInfoListener(pageId, { associatedCookies, requestId, }) {
|
|
443
401
|
if (!associatedCookies || associatedCookies.length === 0) {
|
|
444
402
|
return;
|
|
445
403
|
}
|
|
446
404
|
const cookies = associatedCookies.map((associatedCookie) => {
|
|
447
|
-
var _a, _b, _c, _d, _e, _f;
|
|
448
405
|
const singleCookie = {
|
|
449
406
|
parsedCookie: {
|
|
450
407
|
name: associatedCookie.cookie.name,
|
|
451
408
|
domain: associatedCookie.cookie.domain,
|
|
452
409
|
path: associatedCookie.cookie.path || '/',
|
|
453
410
|
value: associatedCookie.cookie.value,
|
|
454
|
-
samesite:
|
|
411
|
+
samesite: associatedCookie.cookie.sameSite?.toLowerCase() || 'lax',
|
|
455
412
|
expires: associatedCookie.cookie.expires || 'Session',
|
|
456
413
|
httponly: associatedCookie.cookie.httpOnly || false,
|
|
457
414
|
secure: associatedCookie.cookie.secure || false,
|
|
@@ -460,9 +417,9 @@ class BrowserManagement {
|
|
|
460
417
|
networkEvents: {
|
|
461
418
|
requestEvents: [
|
|
462
419
|
{
|
|
463
|
-
type:
|
|
420
|
+
type: REQUEST_EVENT.CDP_REQUEST_WILL_BE_SENT_EXTRA_INFO,
|
|
464
421
|
requestId,
|
|
465
|
-
url:
|
|
422
|
+
url: this.pageRequests[pageId][requestId]?.url || '',
|
|
466
423
|
blocked: associatedCookie.blockedReasons.length > 0,
|
|
467
424
|
timeStamp: Date.now(),
|
|
468
425
|
},
|
|
@@ -471,17 +428,20 @@ class BrowserManagement {
|
|
|
471
428
|
},
|
|
472
429
|
isBlocked: associatedCookie.blockedReasons.length > 0,
|
|
473
430
|
blockedReasons: associatedCookie.blockedReasons,
|
|
474
|
-
exemptionReason: associatedCookie
|
|
475
|
-
url:
|
|
431
|
+
exemptionReason: associatedCookie?.exemptionReason,
|
|
432
|
+
url: this.pageRequests[pageId][requestId]?.url || '',
|
|
476
433
|
headerType: 'request',
|
|
477
434
|
};
|
|
478
|
-
if (
|
|
435
|
+
if (associatedCookie.cookie?.partitionKey) {
|
|
479
436
|
singleCookie.parsedCookie.partitionKey =
|
|
480
|
-
|
|
437
|
+
associatedCookie.cookie?.partitionKey?.topLevelSite;
|
|
481
438
|
}
|
|
482
439
|
return singleCookie;
|
|
483
440
|
});
|
|
484
|
-
this.pageRequests[pageId][requestId] =
|
|
441
|
+
this.pageRequests[pageId][requestId] = {
|
|
442
|
+
...(this.pageRequests[pageId][requestId] || {}),
|
|
443
|
+
cookies,
|
|
444
|
+
};
|
|
485
445
|
}
|
|
486
446
|
pageFrameAttachedListener(pageId, { frameId, parentFrameId }) {
|
|
487
447
|
if (!this.pageFrames[pageId]) {
|
|
@@ -489,245 +449,172 @@ class BrowserManagement {
|
|
|
489
449
|
}
|
|
490
450
|
this.pageFrames[pageId][frameId] = parentFrameId;
|
|
491
451
|
}
|
|
492
|
-
getMainframeIds() {
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
const
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
}
|
|
504
|
-
return pageTargetIds;
|
|
505
|
-
});
|
|
452
|
+
async getMainframeIds() {
|
|
453
|
+
const pageTargetIds = {};
|
|
454
|
+
// This gets targets for all pages.
|
|
455
|
+
const cdpSession = await Object.values(this.pages)[0].createCDPSession();
|
|
456
|
+
const res = await cdpSession.send('Target.getTargets');
|
|
457
|
+
for (const [_url, page] of Object.entries(this.pages)) {
|
|
458
|
+
const constructedUrl = page.url();
|
|
459
|
+
const mainFrameTargetId = res.targetInfos.find(({ url, type }) => constructedUrl === url && type === 'page')?.targetId;
|
|
460
|
+
pageTargetIds[_url] = mainFrameTargetId || '';
|
|
461
|
+
}
|
|
462
|
+
return pageTargetIds;
|
|
506
463
|
}
|
|
507
|
-
attachListenersToPage(pageId) {
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
flatten: true,
|
|
522
|
-
});
|
|
523
|
-
yield cdpSession.send('Network.enable');
|
|
524
|
-
yield cdpSession.send('Page.enable');
|
|
525
|
-
this.pageRequests[pageId] = {};
|
|
526
|
-
this.pageResponses[pageId] = {};
|
|
527
|
-
this.pageResourcesMaps[pageId] = {};
|
|
528
|
-
page.on('response', (ev) => this.responseEventListener(pageId, ev));
|
|
529
|
-
cdpSession.on('Network.responseReceived', (ev) => this.responseReceivedListener(pageId, ev));
|
|
530
|
-
cdpSession.on('Network.responseReceivedExtraInfo', (ev) => this.responseReceivedExtraInfoListener(pageId, ev));
|
|
531
|
-
cdpSession.on('Network.requestWillBeSent', (ev) => this.requestWillBeSentListener(pageId, ev));
|
|
532
|
-
cdpSession.on('Network.requestWillBeSentExtraInfo', (ev) => this.requestWillBeSentExtraInfoListener(pageId, ev));
|
|
533
|
-
cdpSession.on('Page.frameAttached', (ev) => this.pageFrameAttachedListener(pageId, ev));
|
|
534
|
-
this.debugLog('Finished attaching network event listeners');
|
|
464
|
+
async attachListenersToPage(pageId) {
|
|
465
|
+
const page = this.pages[pageId];
|
|
466
|
+
if (!page) {
|
|
467
|
+
throw new Error(`No page with the provided ID was found:${pageId}`);
|
|
468
|
+
}
|
|
469
|
+
this.debugLog('Attaching network event listeners to the page');
|
|
470
|
+
const cdpSession = await page.createCDPSession();
|
|
471
|
+
await cdpSession.send('Target.setAutoAttach', {
|
|
472
|
+
// If this is set to true, debugger will be attached to every new target that is added to the current target.
|
|
473
|
+
autoAttach: true,
|
|
474
|
+
waitForDebuggerOnStart: false,
|
|
475
|
+
//Enables "flat" access to the session via specifying sessionId attribute in the commands.
|
|
476
|
+
// If this is set to true the debugger is also attached to the child targets of that the target it has been attached to.
|
|
477
|
+
flatten: true,
|
|
535
478
|
});
|
|
479
|
+
await cdpSession.send('Network.enable');
|
|
480
|
+
await cdpSession.send('Page.enable');
|
|
481
|
+
this.pageRequests[pageId] = {};
|
|
482
|
+
this.pageResponses[pageId] = {};
|
|
483
|
+
cdpSession.on('Network.responseReceived', (ev) => this.responseReceivedListener(pageId, ev));
|
|
484
|
+
cdpSession.on('Network.responseReceivedExtraInfo', (ev) => this.responseReceivedExtraInfoListener(pageId, ev));
|
|
485
|
+
cdpSession.on('Network.requestWillBeSent', (ev) => this.requestWillBeSentListener(pageId, ev));
|
|
486
|
+
cdpSession.on('Network.requestWillBeSentExtraInfo', (ev) => this.requestWillBeSentExtraInfoListener(pageId, ev));
|
|
487
|
+
cdpSession.on('Page.frameAttached', (ev) => this.pageFrameAttachedListener(pageId, ev));
|
|
488
|
+
this.debugLog('Finished attaching network event listeners');
|
|
536
489
|
}
|
|
537
|
-
getJSCookies(page) {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
return;
|
|
545
|
-
}
|
|
546
|
-
const _JSCookies = yield (0, common_1.resolveWithTimeout)(frame.evaluate(() => {
|
|
547
|
-
// @ts-ignore
|
|
548
|
-
return cookieStore === null || cookieStore === void 0 ? void 0 : cookieStore.getAll();
|
|
549
|
-
}), [], 200);
|
|
550
|
-
const frameCookies = {};
|
|
551
|
-
_JSCookies.forEach((cookie) => {
|
|
552
|
-
var _a;
|
|
553
|
-
if (!cookie.domain) {
|
|
554
|
-
cookie.domain = new URL(frame.url()).hostname;
|
|
555
|
-
}
|
|
556
|
-
if (cookie.domain[0] !== '.') {
|
|
557
|
-
cookie.domain = '.' + cookie.domain;
|
|
558
|
-
}
|
|
559
|
-
const key = cookie.name + ':' + cookie.domain + ':' + cookie.path;
|
|
560
|
-
frameCookies[key] = {
|
|
561
|
-
parsedCookie: Object.assign(Object.assign({}, cookie), { partitionKey: '', httponly: false, samesite: ((_a = cookie.sameSite) === null || _a === void 0 ? void 0 : _a.toLowerCase()) || 'lax' }),
|
|
562
|
-
};
|
|
563
|
-
});
|
|
564
|
-
const frameUrl = new URL(frame.url()).origin;
|
|
565
|
-
cookies[frameUrl] = { frameCookies };
|
|
566
|
-
}
|
|
567
|
-
catch (error) {
|
|
568
|
-
//Fail silently
|
|
490
|
+
async getJSCookies(page) {
|
|
491
|
+
const frames = page.frames();
|
|
492
|
+
const cookies = {};
|
|
493
|
+
await Promise.all(frames.map(async (frame) => {
|
|
494
|
+
try {
|
|
495
|
+
if (!frame.url().includes('http')) {
|
|
496
|
+
return;
|
|
569
497
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
498
|
+
const _JSCookies = await resolveWithTimeout(frame.evaluate(() => {
|
|
499
|
+
// @ts-ignore
|
|
500
|
+
return cookieStore?.getAll();
|
|
501
|
+
}), [], 200);
|
|
502
|
+
const frameCookies = {};
|
|
503
|
+
_JSCookies.forEach((cookie) => {
|
|
504
|
+
if (!cookie.domain) {
|
|
505
|
+
cookie.domain = new URL(frame.url()).hostname;
|
|
506
|
+
}
|
|
507
|
+
if (cookie.domain[0] !== '.') {
|
|
508
|
+
cookie.domain = '.' + cookie.domain;
|
|
509
|
+
}
|
|
510
|
+
const key = cookie.name + ':' + cookie.domain + ':' + cookie.path;
|
|
511
|
+
frameCookies[key] = {
|
|
512
|
+
parsedCookie: {
|
|
513
|
+
...cookie,
|
|
514
|
+
partitionKey: '',
|
|
515
|
+
httponly: false,
|
|
516
|
+
samesite: cookie.sameSite?.toLowerCase() || 'lax',
|
|
517
|
+
},
|
|
518
|
+
};
|
|
519
|
+
});
|
|
520
|
+
const frameUrl = new URL(frame.url()).origin;
|
|
521
|
+
cookies[frameUrl] = { frameCookies };
|
|
522
|
+
}
|
|
523
|
+
catch (error) {
|
|
524
|
+
//Fail silently
|
|
525
|
+
}
|
|
526
|
+
}));
|
|
527
|
+
return cookies;
|
|
573
528
|
}
|
|
529
|
+
// @todo Remove after ensuring that it is not used anywhere except library detection feature.
|
|
574
530
|
getResources(urls) {
|
|
575
531
|
const allFetchedResources = {};
|
|
576
532
|
urls.forEach((url) => {
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
const resources = this.pageResourcesMaps[url];
|
|
580
|
-
if (!page || !resources) {
|
|
581
|
-
allFetchedResources[url] = [];
|
|
582
|
-
return;
|
|
583
|
-
}
|
|
584
|
-
const mainFrameUrl = new URL(page.url()).origin;
|
|
585
|
-
allFetchedResources[mainFrameUrl] = Array.from((_a = Object.values(resources)) !== null && _a !== void 0 ? _a : []);
|
|
533
|
+
allFetchedResources[url] = [];
|
|
534
|
+
return;
|
|
586
535
|
});
|
|
587
536
|
return allFetchedResources;
|
|
588
537
|
}
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
if (!functionDOMQuery) {
|
|
607
|
-
return [];
|
|
608
|
-
}
|
|
609
|
-
return functionDOMQuery();
|
|
610
|
-
}, name.replaceAll('-', ''));
|
|
611
|
-
domQueryMatches[name] = {
|
|
612
|
-
domQuerymatches: queryResult,
|
|
613
|
-
};
|
|
614
|
-
}
|
|
615
|
-
})));
|
|
616
|
-
const mainFrameUrl = new URL(page.url()).origin;
|
|
617
|
-
return { [mainFrameUrl]: domQueryMatches };
|
|
618
|
-
}
|
|
619
|
-
catch (error) {
|
|
620
|
-
if (error instanceof Error) {
|
|
621
|
-
this.pushErrors(url, {
|
|
622
|
-
errorMessage: error.message,
|
|
623
|
-
stackTrace: (_a = error === null || error === void 0 ? void 0 : error.stack) !== null && _a !== void 0 ? _a : '',
|
|
624
|
-
errorName: error === null || error === void 0 ? void 0 : error.name,
|
|
625
|
-
});
|
|
626
|
-
throw error;
|
|
627
|
-
}
|
|
628
|
-
return {};
|
|
538
|
+
async analyzeCookies(userProvidedUrls, shouldSkipAcceptBanner) {
|
|
539
|
+
// Open tabs and attach network listeners
|
|
540
|
+
await Promise.all(userProvidedUrls.map(async (url) => {
|
|
541
|
+
const sitePage = await this.openPage();
|
|
542
|
+
this.pages[url] = sitePage;
|
|
543
|
+
await this.attachListenersToPage(url);
|
|
544
|
+
}));
|
|
545
|
+
// Navigate to URLs
|
|
546
|
+
// eslint-disable-next-line no-useless-catch -- Because we are rethrowing the same error no need to create a new Error instance
|
|
547
|
+
try {
|
|
548
|
+
await Promise.all(userProvidedUrls.map(async (url) => {
|
|
549
|
+
await this.navigateToPage(url);
|
|
550
|
+
}));
|
|
551
|
+
}
|
|
552
|
+
catch (error) {
|
|
553
|
+
if (!this.isSiteMap) {
|
|
554
|
+
throw error;
|
|
629
555
|
}
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
//
|
|
636
|
-
yield Promise.all(userProvidedUrls.map((url) => __awaiter(this, void 0, void 0, function* () {
|
|
637
|
-
const sitePage = yield this.openPage();
|
|
638
|
-
this.pages[url] = sitePage;
|
|
639
|
-
yield this.attachListenersToPage(url);
|
|
640
|
-
})));
|
|
641
|
-
// Navigate to URLs
|
|
642
|
-
// eslint-disable-next-line no-useless-catch -- Because we are rethrowing the same error no need to create a new Error instance
|
|
556
|
+
}
|
|
557
|
+
// Delay for page to load resources
|
|
558
|
+
await delay(this.pageWaitTime / 2);
|
|
559
|
+
// Accept Banners
|
|
560
|
+
if (!shouldSkipAcceptBanner) {
|
|
561
|
+
// delay
|
|
643
562
|
try {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
}))
|
|
563
|
+
await Promise.all(userProvidedUrls.map(async (url) => {
|
|
564
|
+
await this.clickOnAcceptBanner(url);
|
|
565
|
+
}));
|
|
647
566
|
}
|
|
648
567
|
catch (error) {
|
|
649
568
|
if (!this.isSiteMap) {
|
|
650
569
|
throw error;
|
|
651
570
|
}
|
|
652
571
|
}
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
// Scroll to bottom of the page
|
|
670
|
-
yield Promise.all(userProvidedUrls.map((url) => __awaiter(this, void 0, void 0, function* () {
|
|
671
|
-
yield this.pageScroll(url);
|
|
672
|
-
})));
|
|
673
|
-
try {
|
|
674
|
-
yield Promise.all(userProvidedUrls.map((url) => __awaiter(this, void 0, void 0, function* () {
|
|
675
|
-
const newMatches = yield this.insertAndRunDOMQueryFunctions(url, Libraries);
|
|
676
|
-
consolidatedDOMQueryMatches = Object.assign(Object.assign({}, consolidatedDOMQueryMatches), newMatches);
|
|
677
|
-
})));
|
|
572
|
+
}
|
|
573
|
+
// Scroll to bottom of the page
|
|
574
|
+
await Promise.all(userProvidedUrls.map(async (url) => {
|
|
575
|
+
await this.pageScroll(url);
|
|
576
|
+
}));
|
|
577
|
+
// Delay for page to load more resources
|
|
578
|
+
await delay(this.pageWaitTime / 2);
|
|
579
|
+
const mainFrameUrlIdMap = await this.getMainframeIds();
|
|
580
|
+
Object.entries(mainFrameUrlIdMap).forEach(([_url, id]) => {
|
|
581
|
+
if (!this.pageFrames[_url]) {
|
|
582
|
+
this.pageFrames[_url] = {
|
|
583
|
+
[id]: '0',
|
|
584
|
+
};
|
|
678
585
|
}
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
throw error;
|
|
682
|
-
}
|
|
586
|
+
else {
|
|
587
|
+
this.pageFrames[_url][id] = '0';
|
|
683
588
|
}
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
const
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
};
|
|
692
|
-
}
|
|
693
|
-
else {
|
|
694
|
-
this.pageFrames[_url][id] = '0';
|
|
695
|
-
}
|
|
696
|
-
});
|
|
697
|
-
const result = yield Promise.all(userProvidedUrls.map((userProvidedUrl) => __awaiter(this, void 0, void 0, function* () {
|
|
698
|
-
const _responses = this.pageResponses[userProvidedUrl];
|
|
699
|
-
const _requests = this.pageRequests[userProvidedUrl];
|
|
700
|
-
const _page = this.pages[userProvidedUrl];
|
|
701
|
-
const _pageFrames = this.pageFrames[userProvidedUrl];
|
|
702
|
-
if (!_responses || !_requests || !_page) {
|
|
703
|
-
return {
|
|
704
|
-
url: userProvidedUrl,
|
|
705
|
-
cookieData: {},
|
|
706
|
-
};
|
|
707
|
-
}
|
|
708
|
-
const cookieDataFromNetwork = yield (0, parseNetworkDataToCookieData_1.parseNetworkDataToCookieData)(_responses, _requests, _page, _pageFrames);
|
|
709
|
-
const cookieDataFromJS = yield this.getJSCookies(_page);
|
|
710
|
-
const mainFrameUrl = new URL(_page.url()).origin;
|
|
711
|
-
const collatedCookieData = (0, collateCookieData_1.default)(cookieDataFromNetwork, cookieDataFromJS);
|
|
589
|
+
});
|
|
590
|
+
const result = await Promise.all(userProvidedUrls.map(async (userProvidedUrl) => {
|
|
591
|
+
const _responses = this.pageResponses[userProvidedUrl];
|
|
592
|
+
const _requests = this.pageRequests[userProvidedUrl];
|
|
593
|
+
const _page = this.pages[userProvidedUrl];
|
|
594
|
+
const _pageFrames = this.pageFrames[userProvidedUrl];
|
|
595
|
+
if (!_responses || !_requests || !_page) {
|
|
712
596
|
return {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
cookieData: collatedCookieData,
|
|
597
|
+
url: userProvidedUrl,
|
|
598
|
+
cookieData: {},
|
|
716
599
|
};
|
|
717
|
-
}
|
|
600
|
+
}
|
|
601
|
+
const cookieDataFromNetwork = await parseNetworkDataToCookieData(_responses, _requests, _page, _pageFrames);
|
|
602
|
+
const cookieDataFromJS = await this.getJSCookies(_page);
|
|
603
|
+
const mainFrameUrl = new URL(_page.url()).origin;
|
|
604
|
+
const collatedCookieData = collateCookieData(cookieDataFromNetwork, cookieDataFromJS);
|
|
718
605
|
return {
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
606
|
+
// Page may redirect. page.url() gives the redirected URL
|
|
607
|
+
url: mainFrameUrl,
|
|
608
|
+
cookieData: collatedCookieData,
|
|
722
609
|
};
|
|
723
|
-
});
|
|
610
|
+
}));
|
|
611
|
+
return {
|
|
612
|
+
result,
|
|
613
|
+
erroredOutUrls: this.erroredOutUrls,
|
|
614
|
+
};
|
|
724
615
|
}
|
|
725
|
-
deinitialize() {
|
|
726
|
-
|
|
727
|
-
var _a;
|
|
728
|
-
yield ((_a = this.browser) === null || _a === void 0 ? void 0 : _a.close());
|
|
729
|
-
});
|
|
616
|
+
async deinitialize() {
|
|
617
|
+
await this.browser?.close();
|
|
730
618
|
}
|
|
731
619
|
}
|
|
732
|
-
exports.BrowserManagement = BrowserManagement;
|
|
733
620
|
//# sourceMappingURL=index.js.map
|