@crawlee/browser-pool 3.0.3 → 3.0.4-beta.2

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.
@@ -1,13 +1,6 @@
1
1
  'use strict';
2
2
 
3
- /* eslint-disable no-unused-vars */
4
3
  /* eslint-disable no-undef */
5
- /* eslint-disable no-empty */
6
-
7
- let resolveLoading;
8
- const loading = new Promise((resolve) => {
9
- resolveLoading = resolve;
10
- });
11
4
 
12
5
  const isFirefox = navigator.userAgent.includes('Firefox');
13
6
 
@@ -22,7 +15,7 @@ const translator = new Map();
22
15
  const counter = new Map();
23
16
 
24
17
  const getOpenerId = (id) => {
25
- if (typeof id !== 'number') {
18
+ if (typeof id !== 'number' || !Number.isFinite(id)) {
26
19
  throw new Error('Expected `id` to be a number');
27
20
  }
28
21
 
@@ -60,16 +53,24 @@ chrome.cookies.onChanged.addListener(async (changeInfo) => {
60
53
  return;
61
54
  }
62
55
 
63
- const dotIndex = cookie.name.slice(1).indexOf('.');
56
+ const dotIndex = cookie.name.indexOf('.', 1);
64
57
  if (dotIndex === -1) {
65
58
  return;
66
59
  }
67
60
 
68
- const tabId = Number(cookie.name.slice(0, dotIndex));
61
+ const tabId = Number(cookie.name.slice(1, dotIndex));
62
+
63
+ if (!Number.isFinite(tabId)) {
64
+ return;
65
+ }
66
+
69
67
  const realCookieName = cookie.name.slice(dotIndex + 1);
70
68
  const opener = getOpenerId(tabId);
71
69
 
72
70
  if (tabId !== opener) {
71
+ // eslint-disable-next-line no-console
72
+ console.log(`${realCookieName} -> ${keyFromTabId(opener)}`);
73
+
73
74
  await chrome.cookies.remove({
74
75
  name: cookie.name,
75
76
  url: getCookieURL(cookie),
@@ -108,10 +109,32 @@ chrome.webRequest.onBeforeSendHeaders.addListener(
108
109
  cancel: true,
109
110
  };
110
111
  }
112
+
113
+ // This one is for Firefox
114
+ if (header.name.toLowerCase() === 'x-moz' && header.value === 'prefetch' && !(counter.has(details.tabId))) {
115
+ // eslint-disable-next-line no-console
116
+ console.log(details);
117
+ return {
118
+ cancel: true,
119
+ };
120
+ }
121
+
122
+ if (['beacon', 'csp_report', 'ping', 'speculative'].includes(details.type)) {
123
+ // eslint-disable-next-line no-console
124
+ console.log(details);
125
+ return {
126
+ cancel: true,
127
+ };
128
+ }
129
+
130
+ if (details.tabId === -1) {
131
+ // eslint-disable-next-line no-console
132
+ console.log(details);
133
+ }
111
134
  }
112
135
 
113
136
  return {
114
- requestHeaders: details.requestHeaders.filter((header) => header.name !== 'cookie' || header.value !== ''),
137
+ requestHeaders: details.requestHeaders.filter((header) => header.name.toLowerCase() !== 'cookie' || header.value !== ''),
115
138
  };
116
139
  },
117
140
  { urls: ['<all_urls>'] },
@@ -294,7 +317,7 @@ const routes = Object.assign(Object.create(null), {
294
317
  },
295
318
  });
296
319
 
297
- chrome.webNavigation.onCompleted.addListener(async (details) => {
320
+ const onCompleted = async (details) => {
298
321
  const textPlain = 'data:text/plain,';
299
322
 
300
323
  if (details.frameId === 0 && details.url.startsWith(textPlain)) {
@@ -310,7 +333,9 @@ chrome.webNavigation.onCompleted.addListener(async (details) => {
310
333
  if (hash !== '') {
311
334
  try {
312
335
  body = JSON.parse(decodeURIComponent(hash));
313
- } catch {}
336
+ } catch {
337
+ // Empty on purpose.
338
+ }
314
339
  }
315
340
 
316
341
  // Different protocols are required, otherwise `onCompleted` won't be emitted.
@@ -323,7 +348,9 @@ chrome.webNavigation.onCompleted.addListener(async (details) => {
323
348
  // Invalid URL, ignore.
324
349
  }
325
350
  }
326
- });
351
+ };
352
+
353
+ chrome.webNavigation.onCompleted.addListener(onCompleted);
327
354
 
328
355
  // Load content scripts.
329
356
  (async () => {
@@ -383,5 +410,13 @@ chrome.webNavigation.onCompleted.addListener(async (details) => {
383
410
  });
384
411
  });
385
412
 
386
- resolveLoading();
413
+ chrome.tabs.query({}, async (tabs) => {
414
+ for (const tab of tabs) {
415
+ await onCompleted({
416
+ frameId: 0,
417
+ url: tab.url,
418
+ tabId: tab.id,
419
+ });
420
+ }
421
+ });
387
422
  })();