@browserless.io/browserless 2.5.0-beta-4 → 2.6.0

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.
Files changed (191) hide show
  1. package/CHANGELOG.md +14 -2
  2. package/README.md +65 -34
  3. package/build/config.d.ts +2 -2
  4. package/build/config.js +3 -3
  5. package/build/data/classes.json +1 -1
  6. package/build/data/selectors.json +1 -1
  7. package/build/http.d.ts +1 -0
  8. package/build/http.js +1 -0
  9. package/build/routes/chrome/http/content.post.body.json +8 -8
  10. package/build/routes/chrome/http/pdf.post.body.json +8 -8
  11. package/build/routes/chrome/http/scrape.post.body.json +8 -8
  12. package/build/routes/chrome/http/screenshot.post.body.json +9 -9
  13. package/build/routes/chromium/http/content.post.body.json +8 -8
  14. package/build/routes/chromium/http/pdf.post.body.json +8 -8
  15. package/build/routes/chromium/http/scrape.post.body.json +8 -8
  16. package/build/routes/chromium/http/screenshot.post.body.json +9 -9
  17. package/build/routes/management/http/active.get.d.ts +16 -0
  18. package/build/routes/management/http/active.get.js +17 -0
  19. package/build/routes/management/tests/management.spec.js +7 -0
  20. package/build/server.js +1 -1
  21. package/build/types.d.ts +6 -4
  22. package/build/types.js +1 -0
  23. package/build/utils.d.ts +1 -1
  24. package/docker/base/Dockerfile +1 -1
  25. package/extensions/ublock/1p-filters.html +4 -3
  26. package/extensions/ublock/3p-filters.html +3 -3
  27. package/extensions/ublock/_locales/ar/messages.json +16 -4
  28. package/extensions/ublock/_locales/az/messages.json +16 -4
  29. package/extensions/ublock/_locales/be/messages.json +19 -7
  30. package/extensions/ublock/_locales/bg/messages.json +16 -4
  31. package/extensions/ublock/_locales/bn/messages.json +33 -21
  32. package/extensions/ublock/_locales/br_FR/messages.json +33 -21
  33. package/extensions/ublock/_locales/bs/messages.json +16 -4
  34. package/extensions/ublock/_locales/ca/messages.json +16 -4
  35. package/extensions/ublock/_locales/cs/messages.json +16 -4
  36. package/extensions/ublock/_locales/cv/messages.json +16 -4
  37. package/extensions/ublock/_locales/cy/messages.json +16 -4
  38. package/extensions/ublock/_locales/da/messages.json +21 -9
  39. package/extensions/ublock/_locales/de/messages.json +17 -5
  40. package/extensions/ublock/_locales/el/messages.json +16 -4
  41. package/extensions/ublock/_locales/en/messages.json +16 -4
  42. package/extensions/ublock/_locales/en_GB/messages.json +16 -4
  43. package/extensions/ublock/_locales/eo/messages.json +17 -5
  44. package/extensions/ublock/_locales/es/messages.json +16 -4
  45. package/extensions/ublock/_locales/et/messages.json +16 -4
  46. package/extensions/ublock/_locales/eu/messages.json +16 -4
  47. package/extensions/ublock/_locales/fa/messages.json +24 -12
  48. package/extensions/ublock/_locales/fi/messages.json +16 -4
  49. package/extensions/ublock/_locales/fil/messages.json +16 -4
  50. package/extensions/ublock/_locales/fr/messages.json +16 -4
  51. package/extensions/ublock/_locales/fy/messages.json +16 -4
  52. package/extensions/ublock/_locales/gl/messages.json +16 -4
  53. package/extensions/ublock/_locales/gu/messages.json +16 -4
  54. package/extensions/ublock/_locales/he/messages.json +25 -13
  55. package/extensions/ublock/_locales/hi/messages.json +31 -19
  56. package/extensions/ublock/_locales/hr/messages.json +16 -4
  57. package/extensions/ublock/_locales/hu/messages.json +16 -4
  58. package/extensions/ublock/_locales/hy/messages.json +17 -5
  59. package/extensions/ublock/_locales/id/messages.json +16 -4
  60. package/extensions/ublock/_locales/it/messages.json +17 -5
  61. package/extensions/ublock/_locales/ja/messages.json +16 -4
  62. package/extensions/ublock/_locales/ka/messages.json +16 -4
  63. package/extensions/ublock/_locales/kk/messages.json +16 -4
  64. package/extensions/ublock/_locales/kn/messages.json +74 -62
  65. package/extensions/ublock/_locales/ko/messages.json +16 -4
  66. package/extensions/ublock/_locales/lt/messages.json +23 -11
  67. package/extensions/ublock/_locales/lv/messages.json +16 -4
  68. package/extensions/ublock/_locales/mk/messages.json +16 -4
  69. package/extensions/ublock/_locales/ml/messages.json +19 -7
  70. package/extensions/ublock/_locales/mr/messages.json +16 -4
  71. package/extensions/ublock/_locales/ms/messages.json +16 -4
  72. package/extensions/ublock/_locales/nb/messages.json +16 -4
  73. package/extensions/ublock/_locales/nl/messages.json +16 -4
  74. package/extensions/ublock/_locales/no/messages.json +16 -4
  75. package/extensions/ublock/_locales/oc/messages.json +16 -4
  76. package/extensions/ublock/_locales/pa/messages.json +16 -4
  77. package/extensions/ublock/_locales/pl/messages.json +17 -5
  78. package/extensions/ublock/_locales/pt_BR/messages.json +16 -4
  79. package/extensions/ublock/_locales/pt_PT/messages.json +16 -4
  80. package/extensions/ublock/_locales/ro/messages.json +17 -5
  81. package/extensions/ublock/_locales/ru/messages.json +16 -4
  82. package/extensions/ublock/_locales/si/messages.json +16 -4
  83. package/extensions/ublock/_locales/sk/messages.json +16 -4
  84. package/extensions/ublock/_locales/sl/messages.json +16 -4
  85. package/extensions/ublock/_locales/so/messages.json +16 -4
  86. package/extensions/ublock/_locales/sq/messages.json +16 -4
  87. package/extensions/ublock/_locales/sr/messages.json +16 -4
  88. package/extensions/ublock/_locales/sv/messages.json +20 -8
  89. package/extensions/ublock/_locales/sw/messages.json +16 -4
  90. package/extensions/ublock/_locales/ta/messages.json +16 -4
  91. package/extensions/ublock/_locales/te/messages.json +16 -4
  92. package/extensions/ublock/_locales/th/messages.json +42 -30
  93. package/extensions/ublock/_locales/tr/messages.json +19 -7
  94. package/extensions/ublock/_locales/uk/messages.json +16 -4
  95. package/extensions/ublock/_locales/ur/messages.json +16 -4
  96. package/extensions/ublock/_locales/vi/messages.json +16 -4
  97. package/extensions/ublock/_locales/zh_CN/messages.json +16 -4
  98. package/extensions/ublock/_locales/zh_TW/messages.json +42 -30
  99. package/extensions/ublock/assets/assets.json +95 -78
  100. package/extensions/ublock/assets/resources/scriptlets.js +70 -24
  101. package/extensions/ublock/assets/thirdparties/easylist/easylist.txt +6258 -3453
  102. package/extensions/ublock/assets/thirdparties/easylist/easyprivacy.txt +277 -40
  103. package/extensions/ublock/assets/thirdparties/pgl.yoyo.org/as/serverlist +8 -32
  104. package/extensions/ublock/assets/thirdparties/publicsuffix.org/list/effective_tld_names.dat +107 -12
  105. package/extensions/ublock/assets/thirdparties/urlhaus-filter/urlhaus-filter-online.txt +1160 -954
  106. package/extensions/ublock/assets/ublock/badlists.txt +1 -2
  107. package/extensions/ublock/assets/ublock/badware.min.txt +395 -270
  108. package/extensions/ublock/assets/ublock/filters.min.txt +1176 -1238
  109. package/extensions/ublock/assets/ublock/privacy.min.txt +32 -31
  110. package/extensions/ublock/assets/ublock/quick-fixes.min.txt +120 -110
  111. package/extensions/ublock/assets/ublock/unbreak.min.txt +75 -36
  112. package/extensions/ublock/css/1p-filters.css +2 -1
  113. package/extensions/ublock/css/3p-filters.css +1 -16
  114. package/extensions/ublock/css/advanced-settings.css +1 -0
  115. package/extensions/ublock/css/asset-viewer.css +1 -0
  116. package/extensions/ublock/css/code-viewer.css +1 -0
  117. package/extensions/ublock/css/codemirror.css +37 -10
  118. package/extensions/ublock/css/common.css +36 -2
  119. package/extensions/ublock/css/dashboard.css +9 -3
  120. package/extensions/ublock/css/devtools.css +1 -0
  121. package/extensions/ublock/css/document-blocked.css +3 -3
  122. package/extensions/ublock/css/dom-inspector.css +1 -0
  123. package/extensions/ublock/css/dyna-rules.css +1 -0
  124. package/extensions/ublock/css/epicker-ui.css +76 -66
  125. package/extensions/ublock/css/fa-icons.css +1 -0
  126. package/extensions/ublock/css/logger-ui.css +2 -0
  127. package/extensions/ublock/css/popup-fenix.css +1 -0
  128. package/extensions/ublock/css/whitelist.css +1 -0
  129. package/extensions/ublock/dashboard.html +20 -13
  130. package/extensions/ublock/devtools.html +2 -0
  131. package/extensions/ublock/dyna-rules.html +2 -2
  132. package/extensions/ublock/img/flags-of-the-world/np.png +0 -0
  133. package/extensions/ublock/img/fontawesome/fontawesome-defs.svg +1 -0
  134. package/extensions/ublock/js/1p-filters.js +72 -23
  135. package/extensions/ublock/js/3p-filters.js +71 -25
  136. package/extensions/ublock/js/asset-viewer.js +1 -0
  137. package/extensions/ublock/js/assets.js +83 -89
  138. package/extensions/ublock/js/background.js +20 -27
  139. package/extensions/ublock/js/base64-custom.js +1 -102
  140. package/extensions/ublock/js/benchmarks.js +36 -21
  141. package/extensions/ublock/js/biditrie.js +8 -23
  142. package/extensions/ublock/js/broadcast.js +2 -4
  143. package/extensions/ublock/js/cachestorage.js +594 -396
  144. package/extensions/ublock/js/codemirror/search.js +49 -37
  145. package/extensions/ublock/js/codemirror/ubo-static-filtering.js +233 -215
  146. package/extensions/ublock/js/contentscript-extra.js +31 -1
  147. package/extensions/ublock/js/cosmetic-filtering.js +35 -33
  148. package/extensions/ublock/js/dashboard.js +11 -7
  149. package/extensions/ublock/js/devtools.js +22 -0
  150. package/extensions/ublock/js/dom.js +2 -2
  151. package/extensions/ublock/js/dyna-rules.js +17 -16
  152. package/extensions/ublock/js/epicker-ui.js +41 -16
  153. package/extensions/ublock/js/fa-icons.js +1 -0
  154. package/extensions/ublock/js/hntrie.js +10 -25
  155. package/extensions/ublock/js/i18n.js +15 -15
  156. package/extensions/ublock/js/logger-ui.js +9 -6
  157. package/extensions/ublock/js/messaging.js +51 -26
  158. package/extensions/ublock/js/pagestore.js +21 -23
  159. package/extensions/ublock/js/popup-fenix.js +35 -22
  160. package/extensions/ublock/js/redirect-engine.js +15 -30
  161. package/extensions/ublock/js/reverselookup.js +1 -1
  162. package/extensions/ublock/js/s14e-serializer.js +1405 -0
  163. package/extensions/ublock/js/scriptlet-filtering-core.js +1 -1
  164. package/extensions/ublock/js/scriptlets/epicker.js +27 -18
  165. package/extensions/ublock/js/settings.js +32 -21
  166. package/extensions/ublock/js/start.js +121 -62
  167. package/extensions/ublock/js/static-ext-filtering-db.js +6 -6
  168. package/extensions/ublock/js/static-ext-filtering.js +17 -28
  169. package/extensions/ublock/js/static-filtering-parser.js +26 -4
  170. package/extensions/ublock/js/static-net-filtering.js +69 -168
  171. package/extensions/ublock/js/storage.js +178 -155
  172. package/extensions/ublock/js/traffic.js +11 -7
  173. package/extensions/ublock/js/vapi-background.js +49 -62
  174. package/extensions/ublock/js/vapi-client.js +13 -16
  175. package/extensions/ublock/js/webext.js +10 -2
  176. package/extensions/ublock/js/whitelist.js +27 -25
  177. package/extensions/ublock/lib/publicsuffixlist/publicsuffixlist.js +3 -7
  178. package/extensions/ublock/manifest.json +2 -1
  179. package/extensions/ublock/web_accessible_resources/epicker-ui.html +5 -8
  180. package/extensions/ublock/whitelist.html +3 -4
  181. package/package.json +13 -13
  182. package/src/config.ts +3 -4
  183. package/src/http.ts +1 -0
  184. package/src/routes/management/http/active.get.ts +30 -0
  185. package/src/routes/management/tests/management.spec.ts +13 -0
  186. package/src/server.ts +1 -1
  187. package/src/types.ts +2 -1
  188. package/static/docs/swagger.json +57 -11
  189. package/static/docs/swagger.min.json +56 -10
  190. package/static/function/client.js +4155 -3350
  191. package/extensions/ublock/_locales/ku/messages.json +0 -1294
@@ -1299,6 +1299,7 @@ export class AstFilterParser {
1299
1299
  let modifierType = 0;
1300
1300
  let requestTypeCount = 0;
1301
1301
  let unredirectableTypeCount = 0;
1302
+ let badfilter = false;
1302
1303
  for ( let i = 0, n = this.nodeTypeRegisterPtr; i < n; i++ ) {
1303
1304
  const type = this.nodeTypeRegister[i];
1304
1305
  const targetNode = this.nodeTypeLookupTable[type];
@@ -1322,6 +1323,8 @@ export class AstFilterParser {
1322
1323
  realBad = hasValue;
1323
1324
  break;
1324
1325
  case NODE_TYPE_NET_OPTION_NAME_BADFILTER:
1326
+ badfilter = true;
1327
+ /* falls through */
1325
1328
  case NODE_TYPE_NET_OPTION_NAME_NOOP:
1326
1329
  realBad = isNegated || hasValue;
1327
1330
  break;
@@ -1462,6 +1465,9 @@ export class AstFilterParser {
1462
1465
  this.addFlags(AST_FLAG_HAS_ERROR);
1463
1466
  }
1464
1467
  }
1468
+ const requiresTrustedSource = ( ) =>
1469
+ this.options.trustedSource !== true &&
1470
+ isException === false && badfilter === false;
1465
1471
  switch ( modifierType ) {
1466
1472
  case NODE_TYPE_NET_OPTION_NAME_CNAME:
1467
1473
  realBad = abstractTypeCount || behaviorTypeCount || requestTypeCount;
@@ -1489,7 +1495,7 @@ export class AstFilterParser {
1489
1495
  case NODE_TYPE_NET_OPTION_NAME_REPLACE: {
1490
1496
  realBad = abstractTypeCount || behaviorTypeCount || unredirectableTypeCount;
1491
1497
  if ( realBad ) { break; }
1492
- if ( isException !== true && this.options.trustedSource !== true ) {
1498
+ if ( requiresTrustedSource() ) {
1493
1499
  this.astError = AST_ERROR_UNTRUSTED_SOURCE;
1494
1500
  realBad = true;
1495
1501
  break;
@@ -1504,7 +1510,7 @@ export class AstFilterParser {
1504
1510
  case NODE_TYPE_NET_OPTION_NAME_URLTRANSFORM: {
1505
1511
  realBad = abstractTypeCount || behaviorTypeCount || unredirectableTypeCount;
1506
1512
  if ( realBad ) { break; }
1507
- if ( isException !== true && this.options.trustedSource !== true ) {
1513
+ if ( requiresTrustedSource() ) {
1508
1514
  this.astError = AST_ERROR_UNTRUSTED_SOURCE;
1509
1515
  realBad = true;
1510
1516
  break;
@@ -3118,7 +3124,7 @@ class ExtSelectorCompiler {
3118
3124
  // context.
3119
3125
  const cssIdentifier = '[A-Za-z_][\\w-]*';
3120
3126
  const cssClassOrId = `[.#]${cssIdentifier}`;
3121
- const cssAttribute = `\\[${cssIdentifier}(?:[*^$]?="[^"\\]\\\\]+")?\\]`;
3127
+ const cssAttribute = `\\[${cssIdentifier}(?:[*^$]?="[^"\\]\\\\\\x09-\\x0D]+")?\\]`;
3122
3128
  const cssSimple =
3123
3129
  '(?:' +
3124
3130
  `${cssIdentifier}(?:${cssClassOrId})*(?:${cssAttribute})*` + '|' +
@@ -3202,6 +3208,7 @@ class ExtSelectorCompiler {
3202
3208
  'matches-path',
3203
3209
  'min-text-length',
3204
3210
  'others',
3211
+ 'shadow',
3205
3212
  'upward',
3206
3213
  'watch-attr',
3207
3214
  'xpath',
@@ -3458,6 +3465,8 @@ class ExtSelectorCompiler {
3458
3465
 
3459
3466
  // https://github.com/uBlockOrigin/uBlock-issues/issues/2300
3460
3467
  // Unquoted attribute values are parsed as Identifier instead of String.
3468
+ // https://github.com/uBlockOrigin/uBlock-issues/issues/3127
3469
+ // Escape [\t\n\v\f\r]
3461
3470
  astSerializePart(part) {
3462
3471
  const out = [];
3463
3472
  const { data } = part;
@@ -3473,7 +3482,14 @@ class ExtSelectorCompiler {
3473
3482
  if ( typeof value !== 'string' ) {
3474
3483
  value = data.value.name;
3475
3484
  }
3476
- value = value.replace(/["\\]/g, '\\$&');
3485
+ if ( /["\\]/.test(value) ) {
3486
+ value = value.replace(/["\\]/g, '\\$&');
3487
+ }
3488
+ if ( /[\x09-\x0D]/.test(value) ) {
3489
+ value = value.replace(/[\x09-\x0D]/g, s =>
3490
+ `\\${s.charCodeAt(0).toString(16).toUpperCase()} `
3491
+ );
3492
+ }
3477
3493
  let flags = '';
3478
3494
  if ( typeof data.flags === 'string' ) {
3479
3495
  if ( /^(is?|si?)$/.test(data.flags) === false ) { return; }
@@ -3847,6 +3863,8 @@ class ExtSelectorCompiler {
3847
3863
  return this.compileText(arg);
3848
3864
  case 'remove-class':
3849
3865
  return this.compileText(arg);
3866
+ case 'shadow':
3867
+ return this.compileSelector(arg);
3850
3868
  case 'style':
3851
3869
  return this.compileStyleProperties(arg);
3852
3870
  case 'upward':
@@ -3984,6 +4002,10 @@ class ExtSelectorCompiler {
3984
4002
  compileUpwardArgument(s) {
3985
4003
  const i = this.compileInteger(s, 1, 256);
3986
4004
  if ( i !== undefined ) { return i; }
4005
+ return this.compilePlainSelector(s);
4006
+ }
4007
+
4008
+ compilePlainSelector(s) {
3987
4009
  const parts = this.astFromRaw(s, 'selectorList' );
3988
4010
  if ( this.astIsValidSelectorList(parts) !== true ) { return; }
3989
4011
  if ( this.astHasType(parts, 'ProceduralSelector') ) { return; }
@@ -28,7 +28,6 @@
28
28
  import { queueTask, dropTask } from './tasks.js';
29
29
  import BidiTrieContainer from './biditrie.js';
30
30
  import HNTrieContainer from './hntrie.js';
31
- import { sparseBase64 } from './base64-custom.js';
32
31
  import { CompiledListReader } from './static-filtering-io.js';
33
32
  import * as sfp from './static-filtering-parser.js';
34
33
 
@@ -493,17 +492,13 @@ const filterDataReset = ( ) => {
493
492
  filterData.fill(0);
494
493
  filterDataWritePtr = 2;
495
494
  };
496
- const filterDataToSelfie = ( ) => {
497
- return JSON.stringify(Array.from(filterData.subarray(0, filterDataWritePtr)));
498
- };
495
+ const filterDataToSelfie = ( ) =>
496
+ filterData.subarray(0, filterDataWritePtr);
497
+
499
498
  const filterDataFromSelfie = selfie => {
500
- if ( typeof selfie !== 'string' || selfie === '' ) { return false; }
501
- const data = JSON.parse(selfie);
502
- if ( Array.isArray(data) === false ) { return false; }
503
- filterDataGrow(data.length);
504
- filterDataWritePtr = data.length;
505
- filterData.set(data);
506
- filterDataShrink();
499
+ if ( selfie instanceof Int32Array === false ) { return false; }
500
+ filterData = selfie;
501
+ filterDataWritePtr = selfie.length;
507
502
  return true;
508
503
  };
509
504
 
@@ -519,53 +514,15 @@ const filterRefsReset = ( ) => {
519
514
  filterRefs.fill(null);
520
515
  filterRefsWritePtr = 1;
521
516
  };
522
- const filterRefsToSelfie = ( ) => {
523
- const refs = [];
524
- for ( let i = 0; i < filterRefsWritePtr; i++ ) {
525
- const v = filterRefs[i];
526
- if ( v instanceof RegExp ) {
527
- refs.push({ t: 1, s: v.source, f: v.flags });
528
- continue;
529
- }
530
- if ( Array.isArray(v) ) {
531
- refs.push({ t: 2, v });
532
- continue;
533
- }
534
- if ( typeof v !== 'object' || v === null ) {
535
- refs.push({ t: 0, v });
536
- continue;
537
- }
538
- const out = Object.create(null);
539
- for ( const prop of Object.keys(v) ) {
540
- const value = v[prop];
541
- out[prop] = prop.startsWith('$')
542
- ? (typeof value === 'string' ? '' : null)
543
- : value;
544
- }
545
- refs.push({ t: 3, v: out });
546
- }
547
- return JSON.stringify(refs);
548
- };
517
+ const filterRefsToSelfie = ( ) =>
518
+ filterRefs.slice(0, filterRefsWritePtr);
519
+
549
520
  const filterRefsFromSelfie = selfie => {
550
- if ( typeof selfie !== 'string' || selfie === '' ) { return false; }
551
- const refs = JSON.parse(selfie);
552
- if ( Array.isArray(refs) === false ) { return false; }
553
- for ( let i = 0; i < refs.length; i++ ) {
554
- const v = refs[i];
555
- switch ( v.t ) {
556
- case 0:
557
- case 2:
558
- case 3:
559
- filterRefs[i] = v.v;
560
- break;
561
- case 1:
562
- filterRefs[i] = new RegExp(v.s, v.f);
563
- break;
564
- default:
565
- throw new Error('Unknown filter reference!');
566
- }
521
+ if ( Array.isArray(selfie) === false ) { return false; }
522
+ for ( let i = 0, n = selfie.length; i < n; i++ ) {
523
+ filterRefs[i] = selfie[i];
567
524
  }
568
- filterRefsWritePtr = refs.length;
525
+ filterRefsWritePtr = selfie.length;
569
526
  return true;
570
527
  };
571
528
 
@@ -3121,14 +3078,11 @@ const urlTokenizer = new (class {
3121
3078
  }
3122
3079
 
3123
3080
  toSelfie() {
3124
- return sparseBase64.encode(
3125
- this.knownTokens.buffer,
3126
- this.knownTokens.byteLength
3127
- );
3081
+ return this.knownTokens;
3128
3082
  }
3129
3083
 
3130
3084
  fromSelfie(selfie) {
3131
- return sparseBase64.decode(selfie, this.knownTokens.buffer);
3085
+ this.knownTokens = selfie;
3132
3086
  }
3133
3087
 
3134
3088
  // https://github.com/chrisaljoudi/uBlock/issues/1118
@@ -4095,7 +4049,7 @@ FilterCompiler.prototype.FILTER_UNSUPPORTED = 2;
4095
4049
  /******************************************************************************/
4096
4050
  /******************************************************************************/
4097
4051
 
4098
- const FilterContainer = function() {
4052
+ const StaticNetFilteringEngine = function() {
4099
4053
  this.compilerVersion = '10';
4100
4054
  this.selfieVersion = '10';
4101
4055
 
@@ -4113,7 +4067,7 @@ const FilterContainer = function() {
4113
4067
 
4114
4068
  /******************************************************************************/
4115
4069
 
4116
- FilterContainer.prototype.prime = function() {
4070
+ StaticNetFilteringEngine.prototype.prime = function() {
4117
4071
  origHNTrieContainer.reset(
4118
4072
  keyvalStore.getItem('SNFE.origHNTrieContainer.trieDetails')
4119
4073
  );
@@ -4125,7 +4079,7 @@ FilterContainer.prototype.prime = function() {
4125
4079
 
4126
4080
  /******************************************************************************/
4127
4081
 
4128
- FilterContainer.prototype.reset = function() {
4082
+ StaticNetFilteringEngine.prototype.reset = function() {
4129
4083
  this.processedFilterCount = 0;
4130
4084
  this.acceptedCount = 0;
4131
4085
  this.discardedCount = 0;
@@ -4159,7 +4113,7 @@ FilterContainer.prototype.reset = function() {
4159
4113
 
4160
4114
  /******************************************************************************/
4161
4115
 
4162
- FilterContainer.prototype.freeze = function() {
4116
+ StaticNetFilteringEngine.prototype.freeze = function() {
4163
4117
  const unserialize = CompiledListReader.unserialize;
4164
4118
 
4165
4119
  for ( const line of this.goodFilters ) {
@@ -4256,7 +4210,7 @@ FilterContainer.prototype.freeze = function() {
4256
4210
 
4257
4211
  /******************************************************************************/
4258
4212
 
4259
- FilterContainer.prototype.dnrFromCompiled = function(op, context, ...args) {
4213
+ StaticNetFilteringEngine.prototype.dnrFromCompiled = function(op, context, ...args) {
4260
4214
  if ( op === 'begin' ) {
4261
4215
  Object.assign(context, {
4262
4216
  good: new Set(),
@@ -4591,7 +4545,7 @@ FilterContainer.prototype.dnrFromCompiled = function(op, context, ...args) {
4591
4545
 
4592
4546
  /******************************************************************************/
4593
4547
 
4594
- FilterContainer.prototype.addFilterUnit = function(
4548
+ StaticNetFilteringEngine.prototype.addFilterUnit = function(
4595
4549
  bits,
4596
4550
  tokenHash,
4597
4551
  inewunit
@@ -4618,7 +4572,7 @@ FilterContainer.prototype.addFilterUnit = function(
4618
4572
 
4619
4573
  /******************************************************************************/
4620
4574
 
4621
- FilterContainer.prototype.optimize = function(throttle = 0) {
4575
+ StaticNetFilteringEngine.prototype.optimize = function(throttle = 0) {
4622
4576
  if ( this.optimizeTaskId !== undefined ) {
4623
4577
  dropTask(this.optimizeTaskId);
4624
4578
  this.optimizeTaskId = undefined;
@@ -4674,55 +4628,28 @@ FilterContainer.prototype.optimize = function(throttle = 0) {
4674
4628
 
4675
4629
  /******************************************************************************/
4676
4630
 
4677
- FilterContainer.prototype.toSelfie = async function(storage, path) {
4678
- if ( typeof storage !== 'object' || storage === null ) { return; }
4679
- if ( typeof storage.put !== 'function' ) { return; }
4680
-
4631
+ StaticNetFilteringEngine.prototype.toSelfie = function() {
4632
+ this.optimize(0);
4681
4633
  bidiTrieOptimize(true);
4682
- keyvalStore.setItem(
4683
- 'SNFE.origHNTrieContainer.trieDetails',
4634
+ keyvalStore.setItem('SNFE.origHNTrieContainer.trieDetails',
4684
4635
  origHNTrieContainer.optimize()
4685
4636
  );
4686
-
4687
- return Promise.all([
4688
- storage.put(
4689
- `${path}/destHNTrieContainer`,
4690
- destHNTrieContainer.serialize(sparseBase64)
4691
- ),
4692
- storage.put(
4693
- `${path}/origHNTrieContainer`,
4694
- origHNTrieContainer.serialize(sparseBase64)
4695
- ),
4696
- storage.put(
4697
- `${path}/bidiTrie`,
4698
- bidiTrie.serialize(sparseBase64)
4699
- ),
4700
- storage.put(
4701
- `${path}/filterData`,
4702
- filterDataToSelfie()
4703
- ),
4704
- storage.put(
4705
- `${path}/filterRefs`,
4706
- filterRefsToSelfie()
4707
- ),
4708
- storage.put(
4709
- `${path}/main`,
4710
- JSON.stringify({
4711
- version: this.selfieVersion,
4712
- processedFilterCount: this.processedFilterCount,
4713
- acceptedCount: this.acceptedCount,
4714
- discardedCount: this.discardedCount,
4715
- bitsToBucket: Array.from(this.bitsToBucket).map(kv => {
4716
- kv[1] = Array.from(kv[1]);
4717
- return kv;
4718
- }),
4719
- urlTokenizer: urlTokenizer.toSelfie(),
4720
- })
4721
- )
4722
- ]);
4637
+ return {
4638
+ version: this.selfieVersion,
4639
+ processedFilterCount: this.processedFilterCount,
4640
+ acceptedCount: this.acceptedCount,
4641
+ discardedCount: this.discardedCount,
4642
+ bitsToBucket: this.bitsToBucket,
4643
+ urlTokenizer: urlTokenizer.toSelfie(),
4644
+ destHNTrieContainer: destHNTrieContainer.toSelfie(),
4645
+ origHNTrieContainer: origHNTrieContainer.toSelfie(),
4646
+ bidiTrie: bidiTrie.toSelfie(),
4647
+ filterData: filterDataToSelfie(),
4648
+ filterRefs: filterRefsToSelfie(),
4649
+ };
4723
4650
  };
4724
4651
 
4725
- FilterContainer.prototype.serialize = async function() {
4652
+ StaticNetFilteringEngine.prototype.serialize = async function() {
4726
4653
  const selfie = [];
4727
4654
  const storage = {
4728
4655
  put(name, data) {
@@ -4735,53 +4662,27 @@ FilterContainer.prototype.serialize = async function() {
4735
4662
 
4736
4663
  /******************************************************************************/
4737
4664
 
4738
- FilterContainer.prototype.fromSelfie = async function(storage, path) {
4739
- if ( typeof storage !== 'object' || storage === null ) { return; }
4740
- if ( typeof storage.get !== 'function' ) { return; }
4665
+ StaticNetFilteringEngine.prototype.fromSelfie = async function(selfie) {
4666
+ if ( typeof selfie !== 'object' || selfie === null ) { return; }
4741
4667
 
4742
4668
  this.reset();
4743
4669
 
4744
4670
  this.notReady = true;
4745
4671
 
4746
- const results = await Promise.all([
4747
- storage.get(`${path}/main`),
4748
- storage.get(`${path}/destHNTrieContainer`).then(details =>
4749
- destHNTrieContainer.unserialize(details.content, sparseBase64)
4750
- ),
4751
- storage.get(`${path}/origHNTrieContainer`).then(details =>
4752
- origHNTrieContainer.unserialize(details.content, sparseBase64)
4753
- ),
4754
- storage.get(`${path}/bidiTrie`).then(details =>
4755
- bidiTrie.unserialize(details.content, sparseBase64)
4756
- ),
4757
- storage.get(`${path}/filterData`).then(details =>
4758
- filterDataFromSelfie(details.content)
4759
- ),
4760
- storage.get(`${path}/filterRefs`).then(details =>
4761
- filterRefsFromSelfie(details.content)
4762
- ),
4763
- ]);
4764
-
4672
+ const results = [
4673
+ destHNTrieContainer.fromSelfie(selfie.destHNTrieContainer),
4674
+ origHNTrieContainer.fromSelfie(selfie.origHNTrieContainer),
4675
+ bidiTrie.fromSelfie(selfie.bidiTrie),
4676
+ filterDataFromSelfie(selfie.filterData),
4677
+ filterRefsFromSelfie(selfie.filterRefs),
4678
+ ];
4765
4679
  if ( results.slice(1).every(v => v === true) === false ) { return false; }
4766
4680
 
4767
- const details = results[0];
4768
- if ( typeof details !== 'object' || details === null ) { return false; }
4769
- if ( typeof details.content !== 'string' ) { return false; }
4770
- if ( details.content === '' ) { return false; }
4771
- let selfie;
4772
- try {
4773
- selfie = JSON.parse(details.content);
4774
- } catch (ex) {
4775
- }
4776
- if ( typeof selfie !== 'object' || selfie === null ) { return false; }
4777
4681
  if ( selfie.version !== this.selfieVersion ) { return false; }
4778
4682
  this.processedFilterCount = selfie.processedFilterCount;
4779
4683
  this.acceptedCount = selfie.acceptedCount;
4780
4684
  this.discardedCount = selfie.discardedCount;
4781
- this.bitsToBucket = new Map(selfie.bitsToBucket.map(kv => {
4782
- kv[1] = new Map(kv[1]);
4783
- return kv;
4784
- }));
4685
+ this.bitsToBucket = selfie.bitsToBucket;
4785
4686
  urlTokenizer.fromSelfie(selfie.urlTokenizer);
4786
4687
 
4787
4688
  // If this point is never reached, it means the internal state is
@@ -4794,7 +4695,7 @@ FilterContainer.prototype.fromSelfie = async function(storage, path) {
4794
4695
  return true;
4795
4696
  };
4796
4697
 
4797
- FilterContainer.prototype.unserialize = async function(s) {
4698
+ StaticNetFilteringEngine.prototype.unserialize = async function(s) {
4798
4699
  const selfie = new Map(JSON.parse(s));
4799
4700
  const storage = {
4800
4701
  async get(name) {
@@ -4806,13 +4707,13 @@ FilterContainer.prototype.unserialize = async function(s) {
4806
4707
 
4807
4708
  /******************************************************************************/
4808
4709
 
4809
- FilterContainer.prototype.createCompiler = function() {
4710
+ StaticNetFilteringEngine.prototype.createCompiler = function() {
4810
4711
  return new FilterCompiler();
4811
4712
  };
4812
4713
 
4813
4714
  /******************************************************************************/
4814
4715
 
4815
- FilterContainer.prototype.fromCompiled = function(reader) {
4716
+ StaticNetFilteringEngine.prototype.fromCompiled = function(reader) {
4816
4717
  reader.select('NETWORK_FILTERS:GOOD');
4817
4718
  while ( reader.next() ) {
4818
4719
  this.acceptedCount += 1;
@@ -4831,7 +4732,7 @@ FilterContainer.prototype.fromCompiled = function(reader) {
4831
4732
 
4832
4733
  /******************************************************************************/
4833
4734
 
4834
- FilterContainer.prototype.matchAndFetchModifiers = function(
4735
+ StaticNetFilteringEngine.prototype.matchAndFetchModifiers = function(
4835
4736
  fctxt,
4836
4737
  modifierName
4837
4738
  ) {
@@ -5008,7 +4909,7 @@ FilterContainer.prototype.matchAndFetchModifiers = function(
5008
4909
 
5009
4910
  /******************************************************************************/
5010
4911
 
5011
- FilterContainer.prototype.realmMatchString = function(
4912
+ StaticNetFilteringEngine.prototype.realmMatchString = function(
5012
4913
  realmBits,
5013
4914
  typeBits,
5014
4915
  partyBits
@@ -5135,7 +5036,7 @@ FilterContainer.prototype.realmMatchString = function(
5135
5036
  // https://www.reddit.com/r/uBlockOrigin/comments/d6vxzj/
5136
5037
  // Add support for `specifichide`.
5137
5038
 
5138
- FilterContainer.prototype.matchRequestReverse = function(type, url) {
5039
+ StaticNetFilteringEngine.prototype.matchRequestReverse = function(type, url) {
5139
5040
  const typeBits = typeNameToTypeValue[type] | 0x80000000;
5140
5041
 
5141
5042
  // Prime tokenizer: we get a normalized URL in return.
@@ -5184,7 +5085,7 @@ FilterContainer.prototype.matchRequestReverse = function(type, url) {
5184
5085
  *
5185
5086
  * @returns {integer} 0=no match, 1=block, 2=allow (exception)
5186
5087
  */
5187
- FilterContainer.prototype.matchRequest = function(fctxt, modifiers = 0) {
5088
+ StaticNetFilteringEngine.prototype.matchRequest = function(fctxt, modifiers = 0) {
5188
5089
  let typeBits = typeNameToTypeValue[fctxt.type];
5189
5090
  if ( modifiers === 0 ) {
5190
5091
  if ( typeBits === undefined ) {
@@ -5231,7 +5132,7 @@ FilterContainer.prototype.matchRequest = function(fctxt, modifiers = 0) {
5231
5132
 
5232
5133
  /******************************************************************************/
5233
5134
 
5234
- FilterContainer.prototype.matchHeaders = function(fctxt, headers) {
5135
+ StaticNetFilteringEngine.prototype.matchHeaders = function(fctxt, headers) {
5235
5136
  const typeBits = typeNameToTypeValue[fctxt.type] || otherTypeBitValue;
5236
5137
  const partyBits = fctxt.is3rdPartyToDoc() ? THIRDPARTY_REALM : FIRSTPARTY_REALM;
5237
5138
 
@@ -5268,7 +5169,7 @@ FilterContainer.prototype.matchHeaders = function(fctxt, headers) {
5268
5169
 
5269
5170
  /******************************************************************************/
5270
5171
 
5271
- FilterContainer.prototype.redirectRequest = function(redirectEngine, fctxt) {
5172
+ StaticNetFilteringEngine.prototype.redirectRequest = function(redirectEngine, fctxt) {
5272
5173
  const directives = this.matchAndFetchModifiers(fctxt, 'redirect-rule');
5273
5174
  // No directive is the most common occurrence.
5274
5175
  if ( directives === undefined ) { return; }
@@ -5286,7 +5187,7 @@ FilterContainer.prototype.redirectRequest = function(redirectEngine, fctxt) {
5286
5187
  return directives;
5287
5188
  };
5288
5189
 
5289
- FilterContainer.prototype.transformRequest = function(fctxt) {
5190
+ StaticNetFilteringEngine.prototype.transformRequest = function(fctxt) {
5290
5191
  const directives = this.matchAndFetchModifiers(fctxt, 'uritransform');
5291
5192
  if ( directives === undefined ) { return; }
5292
5193
  const redirectURL = new URL(fctxt.url);
@@ -5350,7 +5251,7 @@ function compareRedirectRequests(redirectEngine, a, b) {
5350
5251
  // https://github.com/uBlockOrigin/uBlock-issues/issues/1626
5351
5252
  // Do not redirect when the number of query parameters does not change.
5352
5253
 
5353
- FilterContainer.prototype.filterQuery = function(fctxt) {
5254
+ StaticNetFilteringEngine.prototype.filterQuery = function(fctxt) {
5354
5255
  const directives = this.matchAndFetchModifiers(fctxt, 'removeparam');
5355
5256
  if ( directives === undefined ) { return; }
5356
5257
  const url = fctxt.url;
@@ -5444,14 +5345,14 @@ function parseQueryPruneValue(directive) {
5444
5345
 
5445
5346
  /******************************************************************************/
5446
5347
 
5447
- FilterContainer.prototype.hasQuery = function(fctxt) {
5348
+ StaticNetFilteringEngine.prototype.hasQuery = function(fctxt) {
5448
5349
  urlTokenizer.setURL(fctxt.url);
5449
5350
  return urlTokenizer.hasQuery();
5450
5351
  };
5451
5352
 
5452
5353
  /******************************************************************************/
5453
5354
 
5454
- FilterContainer.prototype.toLogData = function() {
5355
+ StaticNetFilteringEngine.prototype.toLogData = function() {
5455
5356
  if ( this.$filterUnit !== 0 ) {
5456
5357
  return new LogData(this.$catBits, this.$tokenHash, this.$filterUnit);
5457
5358
  }
@@ -5459,19 +5360,19 @@ FilterContainer.prototype.toLogData = function() {
5459
5360
 
5460
5361
  /******************************************************************************/
5461
5362
 
5462
- FilterContainer.prototype.isBlockImportant = function() {
5363
+ StaticNetFilteringEngine.prototype.isBlockImportant = function() {
5463
5364
  return this.$filterUnit !== 0 && $isBlockImportant;
5464
5365
  };
5465
5366
 
5466
5367
  /******************************************************************************/
5467
5368
 
5468
- FilterContainer.prototype.getFilterCount = function() {
5369
+ StaticNetFilteringEngine.prototype.getFilterCount = function() {
5469
5370
  return this.acceptedCount - this.discardedCount;
5470
5371
  };
5471
5372
 
5472
5373
  /******************************************************************************/
5473
5374
 
5474
- FilterContainer.prototype.enableWASM = function(wasmModuleFetcher, path) {
5375
+ StaticNetFilteringEngine.prototype.enableWASM = function(wasmModuleFetcher, path) {
5475
5376
  return Promise.all([
5476
5377
  bidiTrie.enableWASM(wasmModuleFetcher, path),
5477
5378
  origHNTrieContainer.enableWASM(wasmModuleFetcher, path),
@@ -5483,7 +5384,7 @@ FilterContainer.prototype.enableWASM = function(wasmModuleFetcher, path) {
5483
5384
 
5484
5385
  /******************************************************************************/
5485
5386
 
5486
- FilterContainer.prototype.test = async function(docURL, type, url) {
5387
+ StaticNetFilteringEngine.prototype.test = async function(docURL, type, url) {
5487
5388
  const fctxt = new FilteringContext();
5488
5389
  fctxt.setDocOriginFromURL(docURL);
5489
5390
  fctxt.setType(type);
@@ -5497,7 +5398,7 @@ FilterContainer.prototype.test = async function(docURL, type, url) {
5497
5398
 
5498
5399
  /******************************************************************************/
5499
5400
 
5500
- FilterContainer.prototype.bucketHistogram = function() {
5401
+ StaticNetFilteringEngine.prototype.bucketHistogram = function() {
5501
5402
  const results = [];
5502
5403
  for ( const [ bits, bucket ] of this.bitsToBucket ) {
5503
5404
  for ( const [ th, iunit ] of bucket ) {
@@ -5518,7 +5419,7 @@ FilterContainer.prototype.bucketHistogram = function() {
5518
5419
  // Dump the internal state of the filtering engine to the console.
5519
5420
  // Useful to make development decisions and investigate issues.
5520
5421
 
5521
- FilterContainer.prototype.dump = function() {
5422
+ StaticNetFilteringEngine.prototype.dump = function() {
5522
5423
  const thConstants = new Map([
5523
5424
  [ NO_TOKEN_HASH, 'NO_TOKEN_HASH' ],
5524
5425
  [ DOT_TOKEN_HASH, 'DOT_TOKEN_HASH' ],
@@ -5648,6 +5549,6 @@ FilterContainer.prototype.dump = function() {
5648
5549
 
5649
5550
  /******************************************************************************/
5650
5551
 
5651
- const staticNetFilteringEngine = new FilterContainer();
5552
+ const staticNetFilteringEngine = new StaticNetFilteringEngine();
5652
5553
 
5653
5554
  export default staticNetFilteringEngine;