@browserless.io/browserless 2.0.0-beta-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/CHANGELOG.md +674 -0
- package/LICENSE +6 -0
- package/README.md +132 -0
- package/assets/logo.png +0 -0
- package/bin/browserless.js +227 -0
- package/browser.json +7 -0
- package/build/browserless.d.ts +33 -0
- package/build/browserless.js +146 -0
- package/build/browsers/cdp-chromium.d.ts +41 -0
- package/build/browsers/cdp-chromium.js +287 -0
- package/build/browsers/index.d.ts +26 -0
- package/build/browsers/index.js +183 -0
- package/build/browsers/playwright-chromium.d.ts +34 -0
- package/build/browsers/playwright-chromium.js +106 -0
- package/build/browsers/playwright-firefox.d.ts +34 -0
- package/build/browsers/playwright-firefox.js +101 -0
- package/build/browsers/playwright-webkit.d.ts +34 -0
- package/build/browsers/playwright-webkit.js +101 -0
- package/build/config.d.ts +138 -0
- package/build/config.js +349 -0
- package/build/constants.d.ts +4 -0
- package/build/constants.js +4 -0
- package/build/data/classes.json +1 -0
- package/build/data/selectors.json +1 -0
- package/build/exports.d.ts +20 -0
- package/build/exports.js +22 -0
- package/build/file-system.d.ts +24 -0
- package/build/file-system.js +46 -0
- package/build/hooks.d.ts +5 -0
- package/build/hooks.js +20 -0
- package/build/http.d.ts +175 -0
- package/build/http.js +104 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +39 -0
- package/build/limiter.d.ts +24 -0
- package/build/limiter.js +147 -0
- package/build/limiter.spec.d.ts +1 -0
- package/build/limiter.spec.js +241 -0
- package/build/metrics.d.ts +24 -0
- package/build/metrics.js +86 -0
- package/build/metrics.spec.d.ts +1 -0
- package/build/metrics.spec.js +35 -0
- package/build/mime-types.d.ts +1 -0
- package/build/mime-types.js +328 -0
- package/build/monitoring.d.ts +13 -0
- package/build/monitoring.js +38 -0
- package/build/routes/chromium/http/content-post.body.json +514 -0
- package/build/routes/chromium/http/content-post.d.ts +34 -0
- package/build/routes/chromium/http/content-post.js +109 -0
- package/build/routes/chromium/http/content-post.query.json +183 -0
- package/build/routes/chromium/http/content-post.response.json +5 -0
- package/build/routes/chromium/http/download-post.body.json +32 -0
- package/build/routes/chromium/http/download-post.d.ts +16 -0
- package/build/routes/chromium/http/download-post.js +92 -0
- package/build/routes/chromium/http/download-post.query.json +120 -0
- package/build/routes/chromium/http/download-post.response.json +4 -0
- package/build/routes/chromium/http/function-post.body.json +32 -0
- package/build/routes/chromium/http/function-post.d.ts +18 -0
- package/build/routes/chromium/http/function-post.js +53 -0
- package/build/routes/chromium/http/function-post.query.json +120 -0
- package/build/routes/chromium/http/function-post.response.json +4 -0
- package/build/routes/chromium/http/pdf-post.body.json +654 -0
- package/build/routes/chromium/http/pdf-post.d.ts +35 -0
- package/build/routes/chromium/http/pdf-post.js +107 -0
- package/build/routes/chromium/http/pdf-post.query.json +120 -0
- package/build/routes/chromium/http/pdf-post.response.json +5 -0
- package/build/routes/chromium/http/performance.body.json +26 -0
- package/build/routes/chromium/http/performance.d.ts +17 -0
- package/build/routes/chromium/http/performance.js +30 -0
- package/build/routes/chromium/http/performance.query.json +120 -0
- package/build/routes/chromium/http/performance.response.json +7 -0
- package/build/routes/chromium/http/scrape-post.body.json +561 -0
- package/build/routes/chromium/http/scrape-post.d.ts +106 -0
- package/build/routes/chromium/http/scrape-post.js +205 -0
- package/build/routes/chromium/http/scrape-post.query.json +183 -0
- package/build/routes/chromium/http/scrape-post.response.json +325 -0
- package/build/routes/chromium/http/screenshot-post.body.json +604 -0
- package/build/routes/chromium/http/screenshot-post.d.ts +37 -0
- package/build/routes/chromium/http/screenshot-post.js +124 -0
- package/build/routes/chromium/http/screenshot-post.query.json +120 -0
- package/build/routes/chromium/http/screenshot-post.response.json +5 -0
- package/build/routes/chromium/tests/content.spec.d.ts +1 -0
- package/build/routes/chromium/tests/content.spec.js +285 -0
- package/build/routes/chromium/tests/download.spec.d.ts +1 -0
- package/build/routes/chromium/tests/download.spec.js +67 -0
- package/build/routes/chromium/tests/function.spec.d.ts +1 -0
- package/build/routes/chromium/tests/function.spec.js +245 -0
- package/build/routes/chromium/tests/pdf.spec.d.ts +1 -0
- package/build/routes/chromium/tests/pdf.spec.js +333 -0
- package/build/routes/chromium/tests/performance.spec.d.ts +1 -0
- package/build/routes/chromium/tests/performance.spec.js +124 -0
- package/build/routes/chromium/tests/scrape.spec.d.ts +1 -0
- package/build/routes/chromium/tests/scrape.spec.js +354 -0
- package/build/routes/chromium/tests/screenshot.spec.d.ts +1 -0
- package/build/routes/chromium/tests/screenshot.spec.js +339 -0
- package/build/routes/chromium/tests/websocket.spec.d.ts +1 -0
- package/build/routes/chromium/tests/websocket.spec.js +309 -0
- package/build/routes/chromium/utils/function/client.d.ts +26 -0
- package/build/routes/chromium/utils/function/client.js +66 -0
- package/build/routes/chromium/utils/function/handler.d.ts +18 -0
- package/build/routes/chromium/utils/function/handler.js +95 -0
- package/build/routes/chromium/utils/performance/child.d.ts +1 -0
- package/build/routes/chromium/utils/performance/child.js +29 -0
- package/build/routes/chromium/utils/performance/main.d.ts +3 -0
- package/build/routes/chromium/utils/performance/main.js +65 -0
- package/build/routes/chromium/utils/performance/types.d.ts +21 -0
- package/build/routes/chromium/utils/performance/types.js +1 -0
- package/build/routes/chromium/ws/browser.d.ts +6 -0
- package/build/routes/chromium/ws/browser.js +11 -0
- package/build/routes/chromium/ws/browser.query.json +120 -0
- package/build/routes/chromium/ws/cdp-chromium.d.ts +6 -0
- package/build/routes/chromium/ws/cdp-chromium.js +11 -0
- package/build/routes/chromium/ws/cdp-chromium.query.json +120 -0
- package/build/routes/chromium/ws/page.d.ts +6 -0
- package/build/routes/chromium/ws/page.js +11 -0
- package/build/routes/chromium/ws/page.query.json +120 -0
- package/build/routes/chromium/ws/playwright-chromium.d.ts +6 -0
- package/build/routes/chromium/ws/playwright-chromium.js +19 -0
- package/build/routes/chromium/ws/playwright-chromium.query.json +100 -0
- package/build/routes/firefox/tests/websocket.spec.d.ts +1 -0
- package/build/routes/firefox/tests/websocket.spec.js +104 -0
- package/build/routes/firefox/ws/playwright-firefox.d.ts +6 -0
- package/build/routes/firefox/ws/playwright-firefox.js +19 -0
- package/build/routes/firefox/ws/playwright-firefox.query.json +100 -0
- package/build/routes/management/http/config-get.d.ts +25 -0
- package/build/routes/management/http/config-get.js +43 -0
- package/build/routes/management/http/config-get.response.json +107 -0
- package/build/routes/management/http/metrics-get.d.ts +4 -0
- package/build/routes/management/http/metrics-get.js +24 -0
- package/build/routes/management/http/metrics-get.response.json +94 -0
- package/build/routes/management/http/metrics-total-get.d.ts +4 -0
- package/build/routes/management/http/metrics-total-get.js +60 -0
- package/build/routes/management/http/metrics-total-get.response.json +72 -0
- package/build/routes/management/http/sessions-get.d.ts +4 -0
- package/build/routes/management/http/sessions-get.js +21 -0
- package/build/routes/management/http/sessions-get.response.json +221 -0
- package/build/routes/management/http/static-get.d.ts +3 -0
- package/build/routes/management/http/static-get.js +67 -0
- package/build/routes/management/tests/management.spec.d.ts +1 -0
- package/build/routes/management/tests/management.spec.js +41 -0
- package/build/routes/webkit/tests/websocket.spec.d.ts +1 -0
- package/build/routes/webkit/tests/websocket.spec.js +104 -0
- package/build/routes/webkit/ws/playwright-webkit.d.ts +6 -0
- package/build/routes/webkit/ws/playwright-webkit.js +19 -0
- package/build/routes/webkit/ws/playwright-webkit.query.json +100 -0
- package/build/server.d.ts +38 -0
- package/build/server.js +365 -0
- package/build/shim.d.ts +9 -0
- package/build/shim.js +54 -0
- package/build/shim.spec.d.ts +1 -0
- package/build/shim.spec.js +114 -0
- package/build/types.d.ts +360 -0
- package/build/types.js +6 -0
- package/build/utils.d.ts +111 -0
- package/build/utils.js +570 -0
- package/build/webhooks.d.ts +11 -0
- package/build/webhooks.js +43 -0
- package/docker/base/.dockerignore +16 -0
- package/docker/base/Dockerfile +70 -0
- package/docker/chrome/.dockerignore +16 -0
- package/docker/chrome/Dockerfile +40 -0
- package/docker/firefox/.dockerignore +16 -0
- package/docker/firefox/Dockerfile +39 -0
- package/docker/multi/.dockerignore +16 -0
- package/docker/multi/Dockerfile +37 -0
- package/docker/sdk/.dockerignore +16 -0
- package/docker/sdk/Dockerfile +34 -0
- package/docker/webkit/.dockerignore +16 -0
- package/docker/webkit/Dockerfile +40 -0
- package/extensions/screencast/background.js +143 -0
- package/extensions/screencast/content_script.js +18 -0
- package/extensions/screencast/manifest.json +19 -0
- package/extensions/ublock/1p-filters.html +69 -0
- package/extensions/ublock/3p-filters.html +119 -0
- package/extensions/ublock/LICENSE.txt +674 -0
- package/extensions/ublock/_locales/ar/messages.json +1290 -0
- package/extensions/ublock/_locales/az/messages.json +1290 -0
- package/extensions/ublock/_locales/be/messages.json +1290 -0
- package/extensions/ublock/_locales/bg/messages.json +1290 -0
- package/extensions/ublock/_locales/bn/messages.json +1290 -0
- package/extensions/ublock/_locales/br_FR/messages.json +1290 -0
- package/extensions/ublock/_locales/bs/messages.json +1290 -0
- package/extensions/ublock/_locales/ca/messages.json +1290 -0
- package/extensions/ublock/_locales/cs/messages.json +1290 -0
- package/extensions/ublock/_locales/cv/messages.json +1290 -0
- package/extensions/ublock/_locales/da/messages.json +1290 -0
- package/extensions/ublock/_locales/de/messages.json +1290 -0
- package/extensions/ublock/_locales/el/messages.json +1290 -0
- package/extensions/ublock/_locales/en/messages.json +1292 -0
- package/extensions/ublock/_locales/en_GB/messages.json +1290 -0
- package/extensions/ublock/_locales/eo/messages.json +1290 -0
- package/extensions/ublock/_locales/es/messages.json +1290 -0
- package/extensions/ublock/_locales/et/messages.json +1290 -0
- package/extensions/ublock/_locales/eu/messages.json +1290 -0
- package/extensions/ublock/_locales/fa/messages.json +1290 -0
- package/extensions/ublock/_locales/fi/messages.json +1290 -0
- package/extensions/ublock/_locales/fil/messages.json +1290 -0
- package/extensions/ublock/_locales/fr/messages.json +1290 -0
- package/extensions/ublock/_locales/fy/messages.json +1290 -0
- package/extensions/ublock/_locales/gl/messages.json +1290 -0
- package/extensions/ublock/_locales/gu/messages.json +1290 -0
- package/extensions/ublock/_locales/he/messages.json +1290 -0
- package/extensions/ublock/_locales/hi/messages.json +1290 -0
- package/extensions/ublock/_locales/hr/messages.json +1290 -0
- package/extensions/ublock/_locales/hu/messages.json +1290 -0
- package/extensions/ublock/_locales/hy/messages.json +1290 -0
- package/extensions/ublock/_locales/id/messages.json +1290 -0
- package/extensions/ublock/_locales/it/messages.json +1290 -0
- package/extensions/ublock/_locales/ja/messages.json +1290 -0
- package/extensions/ublock/_locales/ka/messages.json +1290 -0
- package/extensions/ublock/_locales/kk/messages.json +1290 -0
- package/extensions/ublock/_locales/kn/messages.json +1290 -0
- package/extensions/ublock/_locales/ko/messages.json +1290 -0
- package/extensions/ublock/_locales/ku/messages.json +1290 -0
- package/extensions/ublock/_locales/lt/messages.json +1290 -0
- package/extensions/ublock/_locales/lv/messages.json +1290 -0
- package/extensions/ublock/_locales/mk/messages.json +1290 -0
- package/extensions/ublock/_locales/ml/messages.json +1290 -0
- package/extensions/ublock/_locales/mr/messages.json +1290 -0
- package/extensions/ublock/_locales/ms/messages.json +1290 -0
- package/extensions/ublock/_locales/nb/messages.json +1290 -0
- package/extensions/ublock/_locales/nl/messages.json +1290 -0
- package/extensions/ublock/_locales/no/messages.json +1290 -0
- package/extensions/ublock/_locales/oc/messages.json +1290 -0
- package/extensions/ublock/_locales/pa/messages.json +1290 -0
- package/extensions/ublock/_locales/pl/messages.json +1290 -0
- package/extensions/ublock/_locales/pt_BR/messages.json +1290 -0
- package/extensions/ublock/_locales/pt_PT/messages.json +1290 -0
- package/extensions/ublock/_locales/ro/messages.json +1290 -0
- package/extensions/ublock/_locales/ru/messages.json +1290 -0
- package/extensions/ublock/_locales/si/messages.json +1290 -0
- package/extensions/ublock/_locales/sk/messages.json +1290 -0
- package/extensions/ublock/_locales/sl/messages.json +1290 -0
- package/extensions/ublock/_locales/so/messages.json +1290 -0
- package/extensions/ublock/_locales/sq/messages.json +1290 -0
- package/extensions/ublock/_locales/sr/messages.json +1290 -0
- package/extensions/ublock/_locales/sv/messages.json +1290 -0
- package/extensions/ublock/_locales/sw/messages.json +1290 -0
- package/extensions/ublock/_locales/ta/messages.json +1290 -0
- package/extensions/ublock/_locales/te/messages.json +1290 -0
- package/extensions/ublock/_locales/th/messages.json +1290 -0
- package/extensions/ublock/_locales/tr/messages.json +1290 -0
- package/extensions/ublock/_locales/uk/messages.json +1290 -0
- package/extensions/ublock/_locales/ur/messages.json +1290 -0
- package/extensions/ublock/_locales/vi/messages.json +1290 -0
- package/extensions/ublock/_locales/zh_CN/messages.json +1290 -0
- package/extensions/ublock/_locales/zh_TW/messages.json +1290 -0
- package/extensions/ublock/about.html +63 -0
- package/extensions/ublock/advanced-settings.html +42 -0
- package/extensions/ublock/asset-viewer.html +50 -0
- package/extensions/ublock/assets/assets.json +903 -0
- package/extensions/ublock/assets/resources/scriptlets.js +4255 -0
- package/extensions/ublock/assets/thirdparties/easylist/easylist.txt +65576 -0
- package/extensions/ublock/assets/thirdparties/easylist/easyprivacy.txt +33219 -0
- package/extensions/ublock/assets/thirdparties/pgl.yoyo.org/as/README.md +29 -0
- package/extensions/ublock/assets/thirdparties/pgl.yoyo.org/as/serverlist +3732 -0
- package/extensions/ublock/assets/thirdparties/publicsuffix.org/list/effective_tld_names.dat +15431 -0
- package/extensions/ublock/assets/thirdparties/urlhaus-filter/LICENSE.md +42 -0
- package/extensions/ublock/assets/thirdparties/urlhaus-filter/urlhaus-filter-online.txt +1970 -0
- package/extensions/ublock/assets/ublock/badlists.txt +77 -0
- package/extensions/ublock/assets/ublock/badware.min.txt +3033 -0
- package/extensions/ublock/assets/ublock/filters.min.txt +23419 -0
- package/extensions/ublock/assets/ublock/privacy.min.txt +575 -0
- package/extensions/ublock/assets/ublock/quick-fixes.min.txt +99 -0
- package/extensions/ublock/assets/ublock/unbreak.min.txt +2448 -0
- package/extensions/ublock/background.html +12 -0
- package/extensions/ublock/cloud-ui.html +23 -0
- package/extensions/ublock/code-viewer.html +53 -0
- package/extensions/ublock/css/1p-filters.css +26 -0
- package/extensions/ublock/css/3p-filters.css +250 -0
- package/extensions/ublock/css/about.css +3 -0
- package/extensions/ublock/css/advanced-settings.css +26 -0
- package/extensions/ublock/css/asset-viewer.css +79 -0
- package/extensions/ublock/css/click2load.css +53 -0
- package/extensions/ublock/css/cloud-ui.css +104 -0
- package/extensions/ublock/css/code-viewer.css +67 -0
- package/extensions/ublock/css/codemirror.css +326 -0
- package/extensions/ublock/css/common.css +347 -0
- package/extensions/ublock/css/dashboard-common.css +55 -0
- package/extensions/ublock/css/dashboard.css +115 -0
- package/extensions/ublock/css/devtools.css +22 -0
- package/extensions/ublock/css/document-blocked.css +146 -0
- package/extensions/ublock/css/dyna-rules.css +79 -0
- package/extensions/ublock/css/epicker-ui.css +270 -0
- package/extensions/ublock/css/fa-icons.css +149 -0
- package/extensions/ublock/css/fonts/Inter/Inter-Regular.woff2 +0 -0
- package/extensions/ublock/css/fonts/Inter/Inter-SemiBold.woff2 +0 -0
- package/extensions/ublock/css/fonts/Inter/LICENSE.txt +93 -0
- package/extensions/ublock/css/fonts/Metropolis/Metropolis-Regular.woff2 +0 -0
- package/extensions/ublock/css/fonts/Metropolis/Metropolis-SemiBold.woff2 +0 -0
- package/extensions/ublock/css/fonts/Metropolis/README.md +25 -0
- package/extensions/ublock/css/fonts/Metropolis/UNLICENSE +24 -0
- package/extensions/ublock/css/logger-ui-inspector.css +116 -0
- package/extensions/ublock/css/logger-ui.css +978 -0
- package/extensions/ublock/css/popup-fenix.css +778 -0
- package/extensions/ublock/css/settings.css +74 -0
- package/extensions/ublock/css/support.css +110 -0
- package/extensions/ublock/css/themes/default.css +526 -0
- package/extensions/ublock/css/whitelist.css +22 -0
- package/extensions/ublock/dashboard.html +47 -0
- package/extensions/ublock/devtools.html +58 -0
- package/extensions/ublock/document-blocked.html +64 -0
- package/extensions/ublock/dyna-rules.html +67 -0
- package/extensions/ublock/img/cloud.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/README +9 -0
- package/extensions/ublock/img/flags-of-the-world/ad.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ae.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/af.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ag.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ai.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/al.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/am.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ao.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/aq.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ar.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/as.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/at.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/au.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/aw.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ax.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/az.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ba.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bb.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bd.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/be.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bf.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bh.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bi.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bj.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bl.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bo.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bq.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/br.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bs.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bt.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bv.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bw.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/by.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/bz.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ca.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cc.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cd.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cf.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ch.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ci.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ck.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cl.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/co.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cu.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cv.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cw.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cx.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cy.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/cz.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/de.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/dj.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/dk.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/dm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/do.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/dz.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ec.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ee.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/eg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/eh.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/er.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/es.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/et.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/fi.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/fj.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/fk.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/fm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/fo.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/fr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ga.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gb-eng.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gb-nir.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gb-sct.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gb-wls.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gb.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gd.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ge.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gf.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gh.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gi.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gl.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gp.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gq.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gs.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gt.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gu.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gw.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/gy.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/hk.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/hm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/hn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/hr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ht.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/hu.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/id.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ie.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/il.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/im.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/in.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/io.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/iq.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ir.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/is.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/it.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/je.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/jm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/jo.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/jp.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ke.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/kg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/kh.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ki.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/km.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/kn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/kp.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/kr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/kw.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ky.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/kz.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/la.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/lb.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/lc.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/li.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/lk.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/lr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ls.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/lt.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/lu.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/lv.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ly.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ma.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mc.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/md.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/me.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mf.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mh.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mk.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ml.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mo.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mp.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mq.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ms.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mt.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mu.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mv.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mw.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mx.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/my.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/mz.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/na.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/nc.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ne.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/nf.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ng.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ni.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/nl.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/no.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/np.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/nr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/nu.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/nz.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/om.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pa.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pe.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pf.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ph.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pk.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pl.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ps.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pt.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/pw.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/py.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/qa.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/re.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ro.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/rs.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ru.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/rw.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sa.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sb.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sc.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sd.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/se.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sh.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/si.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sj.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sk.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sl.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/so.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ss.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/st.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sv.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sx.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sy.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/sz.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tc.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/td.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tf.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/th.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tj.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tk.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tl.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/to.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tr.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tt.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tv.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tw.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/tz.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ua.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ug.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/um.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/us.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/uy.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/uz.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/va.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/vc.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ve.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/vg.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/vi.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/vn.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/vu.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/wf.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ws.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/xk.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/ye.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/yt.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/za.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/zm.png +0 -0
- package/extensions/ublock/img/flags-of-the-world/zw.png +0 -0
- package/extensions/ublock/img/fontawesome/LICENSE.txt +25 -0
- package/extensions/ublock/img/fontawesome/fontawesome-defs.svg +79 -0
- package/extensions/ublock/img/help16.png +0 -0
- package/extensions/ublock/img/icon_128.png +0 -0
- package/extensions/ublock/img/icon_16-loading.png +0 -0
- package/extensions/ublock/img/icon_16-off.png +0 -0
- package/extensions/ublock/img/icon_16.png +0 -0
- package/extensions/ublock/img/icon_32-loading.png +0 -0
- package/extensions/ublock/img/icon_32-off.png +0 -0
- package/extensions/ublock/img/icon_32.png +0 -0
- package/extensions/ublock/img/icon_64-loading.png +0 -0
- package/extensions/ublock/img/icon_64-off.png +0 -0
- package/extensions/ublock/img/icon_64.png +0 -0
- package/extensions/ublock/img/material-design.svg +16 -0
- package/extensions/ublock/img/photon.svg +16 -0
- package/extensions/ublock/img/ublock-defs.svg +27 -0
- package/extensions/ublock/img/ublock.svg +44 -0
- package/extensions/ublock/is-webrtc-supported.html +9 -0
- package/extensions/ublock/js/1p-filters.js +336 -0
- package/extensions/ublock/js/3p-filters.js +867 -0
- package/extensions/ublock/js/about.js +34 -0
- package/extensions/ublock/js/advanced-settings.js +194 -0
- package/extensions/ublock/js/asset-viewer.js +112 -0
- package/extensions/ublock/js/assets.js +1448 -0
- package/extensions/ublock/js/background.js +404 -0
- package/extensions/ublock/js/base64-custom.js +246 -0
- package/extensions/ublock/js/benchmarks.js +421 -0
- package/extensions/ublock/js/biditrie.js +947 -0
- package/extensions/ublock/js/cachestorage.js +510 -0
- package/extensions/ublock/js/click2load.js +60 -0
- package/extensions/ublock/js/cloud-ui.js +238 -0
- package/extensions/ublock/js/code-viewer.js +311 -0
- package/extensions/ublock/js/codemirror/search-thread.js +199 -0
- package/extensions/ublock/js/codemirror/search.js +504 -0
- package/extensions/ublock/js/codemirror/ubo-dynamic-filtering.js +239 -0
- package/extensions/ublock/js/codemirror/ubo-static-filtering.js +1126 -0
- package/extensions/ublock/js/commands.js +181 -0
- package/extensions/ublock/js/console.js +59 -0
- package/extensions/ublock/js/contentscript-extra.js +662 -0
- package/extensions/ublock/js/contentscript.js +1366 -0
- package/extensions/ublock/js/contextmenu.js +270 -0
- package/extensions/ublock/js/cosmetic-filtering.js +983 -0
- package/extensions/ublock/js/dashboard-common.js +215 -0
- package/extensions/ublock/js/dashboard.js +166 -0
- package/extensions/ublock/js/devtools.js +184 -0
- package/extensions/ublock/js/diff-updater.js +288 -0
- package/extensions/ublock/js/document-blocked.js +230 -0
- package/extensions/ublock/js/dom.js +213 -0
- package/extensions/ublock/js/dyna-rules.js +678 -0
- package/extensions/ublock/js/dynamic-net-filtering.js +488 -0
- package/extensions/ublock/js/epicker-ui.js +924 -0
- package/extensions/ublock/js/fa-icons.js +129 -0
- package/extensions/ublock/js/filtering-context.js +461 -0
- package/extensions/ublock/js/filtering-engines.js +50 -0
- package/extensions/ublock/js/hnswitches.js +289 -0
- package/extensions/ublock/js/hntrie.js +780 -0
- package/extensions/ublock/js/html-filtering.js +465 -0
- package/extensions/ublock/js/httpheader-filtering.js +213 -0
- package/extensions/ublock/js/i18n.js +346 -0
- package/extensions/ublock/js/is-webrtc-supported.js +52 -0
- package/extensions/ublock/js/logger-ui-inspector.js +652 -0
- package/extensions/ublock/js/logger-ui.js +3028 -0
- package/extensions/ublock/js/logger.js +84 -0
- package/extensions/ublock/js/lz4.js +190 -0
- package/extensions/ublock/js/messaging.js +2095 -0
- package/extensions/ublock/js/pagestore.js +1140 -0
- package/extensions/ublock/js/popup-fenix.js +1529 -0
- package/extensions/ublock/js/redirect-engine.js +494 -0
- package/extensions/ublock/js/redirect-resources.js +193 -0
- package/extensions/ublock/js/reverselookup-worker.js +287 -0
- package/extensions/ublock/js/reverselookup.js +223 -0
- package/extensions/ublock/js/scriptlet-filtering.js +556 -0
- package/extensions/ublock/js/scriptlets/cosmetic-logger.js +376 -0
- package/extensions/ublock/js/scriptlets/cosmetic-off.js +48 -0
- package/extensions/ublock/js/scriptlets/cosmetic-on.js +48 -0
- package/extensions/ublock/js/scriptlets/cosmetic-report.js +142 -0
- package/extensions/ublock/js/scriptlets/dom-inspector.js +906 -0
- package/extensions/ublock/js/scriptlets/dom-survey-elements.js +72 -0
- package/extensions/ublock/js/scriptlets/dom-survey-scripts.js +126 -0
- package/extensions/ublock/js/scriptlets/epicker.js +1365 -0
- package/extensions/ublock/js/scriptlets/load-3p-css.js +67 -0
- package/extensions/ublock/js/scriptlets/load-large-media-all.js +62 -0
- package/extensions/ublock/js/scriptlets/load-large-media-interactive.js +299 -0
- package/extensions/ublock/js/scriptlets/noscript-spoof.js +89 -0
- package/extensions/ublock/js/scriptlets/should-inject-contentscript.js +40 -0
- package/extensions/ublock/js/scriptlets/subscriber.js +113 -0
- package/extensions/ublock/js/scriptlets/updater.js +101 -0
- package/extensions/ublock/js/settings.js +317 -0
- package/extensions/ublock/js/start.js +509 -0
- package/extensions/ublock/js/static-dnr-filtering.js +497 -0
- package/extensions/ublock/js/static-ext-filtering-db.js +171 -0
- package/extensions/ublock/js/static-ext-filtering.js +184 -0
- package/extensions/ublock/js/static-filtering-io.js +144 -0
- package/extensions/ublock/js/static-filtering-parser.js +4459 -0
- package/extensions/ublock/js/static-net-filtering.js +5631 -0
- package/extensions/ublock/js/storage.js +1683 -0
- package/extensions/ublock/js/support.js +335 -0
- package/extensions/ublock/js/tab.js +1178 -0
- package/extensions/ublock/js/tasks.js +42 -0
- package/extensions/ublock/js/text-encode.js +275 -0
- package/extensions/ublock/js/text-utils.js +107 -0
- package/extensions/ublock/js/theme.js +151 -0
- package/extensions/ublock/js/traffic.js +1260 -0
- package/extensions/ublock/js/ublock.js +696 -0
- package/extensions/ublock/js/uri-utils.js +175 -0
- package/extensions/ublock/js/url-net-filtering.js +336 -0
- package/extensions/ublock/js/utils.js +208 -0
- package/extensions/ublock/js/vapi-background-ext.js +254 -0
- package/extensions/ublock/js/vapi-background.js +1802 -0
- package/extensions/ublock/js/vapi-client-extra.js +312 -0
- package/extensions/ublock/js/vapi-client.js +280 -0
- package/extensions/ublock/js/vapi-common.js +308 -0
- package/extensions/ublock/js/vapi.js +89 -0
- package/extensions/ublock/js/wasm/README.md +24 -0
- package/extensions/ublock/js/wasm/biditrie.wasm +0 -0
- package/extensions/ublock/js/wasm/biditrie.wat +728 -0
- package/extensions/ublock/js/wasm/hntrie.wasm +0 -0
- package/extensions/ublock/js/wasm/hntrie.wat +724 -0
- package/extensions/ublock/js/webext.js +164 -0
- package/extensions/ublock/js/whitelist.js +258 -0
- package/extensions/ublock/lib/codemirror/LICENSE +21 -0
- package/extensions/ublock/lib/codemirror/README.md +47 -0
- package/extensions/ublock/lib/codemirror/addon/comment/comment.js +211 -0
- package/extensions/ublock/lib/codemirror/addon/display/panel.js +133 -0
- package/extensions/ublock/lib/codemirror/addon/edit/closebrackets.js +201 -0
- package/extensions/ublock/lib/codemirror/addon/edit/matchbrackets.js +160 -0
- package/extensions/ublock/lib/codemirror/addon/fold/foldcode.js +157 -0
- package/extensions/ublock/lib/codemirror/addon/fold/foldgutter.css +20 -0
- package/extensions/ublock/lib/codemirror/addon/fold/foldgutter.js +163 -0
- package/extensions/ublock/lib/codemirror/addon/hint/show-hint.css +36 -0
- package/extensions/ublock/lib/codemirror/addon/hint/show-hint.js +509 -0
- package/extensions/ublock/lib/codemirror/addon/merge/merge.css +119 -0
- package/extensions/ublock/lib/codemirror/addon/merge/merge.js +1006 -0
- package/extensions/ublock/lib/codemirror/addon/scroll/annotatescrollbar.js +128 -0
- package/extensions/ublock/lib/codemirror/addon/search/matchesonscrollbar.css +8 -0
- package/extensions/ublock/lib/codemirror/addon/search/searchcursor.js +296 -0
- package/extensions/ublock/lib/codemirror/addon/selection/active-line.js +72 -0
- package/extensions/ublock/lib/codemirror/lib/codemirror.css +350 -0
- package/extensions/ublock/lib/codemirror/lib/codemirror.js +9800 -0
- package/extensions/ublock/lib/codemirror/mode/css/css.js +864 -0
- package/extensions/ublock/lib/codemirror/mode/htmlmixed/htmlmixed.js +153 -0
- package/extensions/ublock/lib/codemirror/mode/javascript/javascript.js +942 -0
- package/extensions/ublock/lib/codemirror/mode/xml/xml.js +413 -0
- package/extensions/ublock/lib/codemirror/theme/night.css +27 -0
- package/extensions/ublock/lib/csstree/LICENSE +19 -0
- package/extensions/ublock/lib/csstree/css-tree.js +17 -0
- package/extensions/ublock/lib/diff/README.md +34 -0
- package/extensions/ublock/lib/diff/swatinem_diff.js +272 -0
- package/extensions/ublock/lib/hsluv/LICENSE +20 -0
- package/extensions/ublock/lib/hsluv/README +3 -0
- package/extensions/ublock/lib/hsluv/hsluv-0.1.0.min.js +8 -0
- package/extensions/ublock/lib/js-beautify/LICENSE +9 -0
- package/extensions/ublock/lib/js-beautify/README +5 -0
- package/extensions/ublock/lib/js-beautify/beautifier.min.js +2 -0
- package/extensions/ublock/lib/lz4/README.md +52 -0
- package/extensions/ublock/lib/lz4/lz4-block-codec-any.js +151 -0
- package/extensions/ublock/lib/lz4/lz4-block-codec-js.js +297 -0
- package/extensions/ublock/lib/lz4/lz4-block-codec-wasm.js +195 -0
- package/extensions/ublock/lib/lz4/lz4-block-codec.wasm +0 -0
- package/extensions/ublock/lib/lz4/lz4-block-codec.wat +745 -0
- package/extensions/ublock/lib/publicsuffixlist/publicsuffixlist.js +641 -0
- package/extensions/ublock/lib/publicsuffixlist/wasm/README.md +29 -0
- package/extensions/ublock/lib/publicsuffixlist/wasm/publicsuffixlist.wasm +0 -0
- package/extensions/ublock/lib/publicsuffixlist/wasm/publicsuffixlist.wat +322 -0
- package/extensions/ublock/lib/punycode.js +493 -0
- package/extensions/ublock/lib/regexanalyzer/CHANGES.md +15 -0
- package/extensions/ublock/lib/regexanalyzer/README.md +14 -0
- package/extensions/ublock/lib/regexanalyzer/regex.js +2276 -0
- package/extensions/ublock/logger-ui.html +232 -0
- package/extensions/ublock/managed_storage.json +73 -0
- package/extensions/ublock/manifest.json +115 -0
- package/extensions/ublock/no-dashboard.html +27 -0
- package/extensions/ublock/popup-fenix.html +114 -0
- package/extensions/ublock/settings.html +98 -0
- package/extensions/ublock/support.html +131 -0
- package/extensions/ublock/web_accessible_resources/1x1.gif +0 -0
- package/extensions/ublock/web_accessible_resources/2x2.png +0 -0
- package/extensions/ublock/web_accessible_resources/32x32.png +0 -0
- package/extensions/ublock/web_accessible_resources/3x2.png +0 -0
- package/extensions/ublock/web_accessible_resources/README.txt +11 -0
- package/extensions/ublock/web_accessible_resources/addthis_widget.js +39 -0
- package/extensions/ublock/web_accessible_resources/amazon_ads.js +70 -0
- package/extensions/ublock/web_accessible_resources/amazon_apstag.js +62 -0
- package/extensions/ublock/web_accessible_resources/ampproject_v0.js +34 -0
- package/extensions/ublock/web_accessible_resources/chartbeat.js +30 -0
- package/extensions/ublock/web_accessible_resources/click2load.html +28 -0
- package/extensions/ublock/web_accessible_resources/doubleclick_instream_ad_status.js +1 -0
- package/extensions/ublock/web_accessible_resources/empty +0 -0
- package/extensions/ublock/web_accessible_resources/epicker-ui.html +76 -0
- package/extensions/ublock/web_accessible_resources/fingerprint2.js +55 -0
- package/extensions/ublock/web_accessible_resources/fingerprint3.js +45 -0
- package/extensions/ublock/web_accessible_resources/google-analytics_analytics.js +110 -0
- package/extensions/ublock/web_accessible_resources/google-analytics_cx_api.js +36 -0
- package/extensions/ublock/web_accessible_resources/google-analytics_ga.js +130 -0
- package/extensions/ublock/web_accessible_resources/google-analytics_inpage_linkid.js +28 -0
- package/extensions/ublock/web_accessible_resources/google-ima.js +855 -0
- package/extensions/ublock/web_accessible_resources/googlesyndication_adsbygoogle.js +56 -0
- package/extensions/ublock/web_accessible_resources/googletagmanager_gtm.js +43 -0
- package/extensions/ublock/web_accessible_resources/googletagservices_gpt.js +153 -0
- package/extensions/ublock/web_accessible_resources/hd-main.js +46 -0
- package/extensions/ublock/web_accessible_resources/ligatus_angular-tag.js +29 -0
- package/extensions/ublock/web_accessible_resources/monkeybroker.js +43 -0
- package/extensions/ublock/web_accessible_resources/mxpnl_mixpanel.js +51 -0
- package/extensions/ublock/web_accessible_resources/nobab.js +87 -0
- package/extensions/ublock/web_accessible_resources/nobab2.js +42 -0
- package/extensions/ublock/web_accessible_resources/noeval-silent.js +28 -0
- package/extensions/ublock/web_accessible_resources/noeval.js +30 -0
- package/extensions/ublock/web_accessible_resources/nofab.js +67 -0
- package/extensions/ublock/web_accessible_resources/noop-0.1s.mp3 +0 -0
- package/extensions/ublock/web_accessible_resources/noop-0.5s.mp3 +0 -0
- package/extensions/ublock/web_accessible_resources/noop-1s.mp4 +0 -0
- package/extensions/ublock/web_accessible_resources/noop-vmap1.0.xml +1 -0
- package/extensions/ublock/web_accessible_resources/noop.css +1 -0
- package/extensions/ublock/web_accessible_resources/noop.html +5 -0
- package/extensions/ublock/web_accessible_resources/noop.js +3 -0
- package/extensions/ublock/web_accessible_resources/noop.json +1 -0
- package/extensions/ublock/web_accessible_resources/noop.txt +1 -0
- package/extensions/ublock/web_accessible_resources/outbrain-widget.js +72 -0
- package/extensions/ublock/web_accessible_resources/popads-dummy.js +30 -0
- package/extensions/ublock/web_accessible_resources/popads.js +40 -0
- package/extensions/ublock/web_accessible_resources/prebid-ads.js +26 -0
- package/extensions/ublock/web_accessible_resources/scorecardresearch_beacon.js +31 -0
- package/extensions/ublock/whitelist.html +63 -0
- package/external/.gitkeep +0 -0
- package/fonts/Calibri Bold Italic.ttf +0 -0
- package/fonts/Calibri Bold.TTF +0 -0
- package/fonts/Calibri Italic.ttf +0 -0
- package/fonts/Calibri Light Italic.ttf +0 -0
- package/fonts/Calibri Light.ttf +0 -0
- package/fonts/Calibri Regular.ttf +0 -0
- package/fonts/Emoji.ttf +0 -0
- package/fonts/SegoeUI-Bold.ttf +0 -0
- package/fonts/SegoeUI-Light.ttf +0 -0
- package/fonts/SegoeUI-Regular.ttf +0 -0
- package/fonts/SegoeUI-Semibold.ttf +0 -0
- package/fonts/SegoeUI-Semilight.ttf +0 -0
- package/fonts/Tahoma Bold.ttf +0 -0
- package/fonts/Tahoma.ttf +0 -0
- package/fonts/fonts.conf +21 -0
- package/package.json +177 -0
- package/scripts/build-function.js +18 -0
- package/scripts/build-open-api.js +274 -0
- package/scripts/build-schemas.js +86 -0
- package/scripts/build-selectors.js +36 -0
- package/scripts/clean.js +7 -0
- package/scripts/install-adblock.js +45 -0
- package/scripts/install-cdp-json.js +37 -0
- package/scripts/start.sh +30 -0
- package/scripts/test.sh +17 -0
- package/src/browserless.ts +253 -0
- package/src/browsers/cdp-chromium.ts +422 -0
- package/src/browsers/index.ts +296 -0
- package/src/browsers/playwright-chromium.ts +168 -0
- package/src/browsers/playwright-firefox.ts +161 -0
- package/src/browsers/playwright-webkit.ts +161 -0
- package/src/config.ts +426 -0
- package/src/constants.ts +4 -0
- package/src/exports.ts +23 -0
- package/src/file-system.ts +54 -0
- package/src/hooks.ts +37 -0
- package/src/http.ts +157 -0
- package/src/index.ts +41 -0
- package/src/limiter.spec.ts +365 -0
- package/src/limiter.ts +225 -0
- package/src/metrics.spec.ts +49 -0
- package/src/metrics.ts +108 -0
- package/src/mime-types.ts +332 -0
- package/src/monitoring.ts +53 -0
- package/src/routes/chromium/http/content-post.ts +238 -0
- package/src/routes/chromium/http/download-post.ts +162 -0
- package/src/routes/chromium/http/function-post.ts +98 -0
- package/src/routes/chromium/http/pdf-post.ts +234 -0
- package/src/routes/chromium/http/performance.ts +71 -0
- package/src/routes/chromium/http/scrape-post.ts +439 -0
- package/src/routes/chromium/http/screenshot-post.ts +262 -0
- package/src/routes/chromium/tests/content.spec.ts +340 -0
- package/src/routes/chromium/tests/download.spec.ts +77 -0
- package/src/routes/chromium/tests/function.spec.ts +279 -0
- package/src/routes/chromium/tests/pdf.spec.ts +375 -0
- package/src/routes/chromium/tests/performance.spec.ts +155 -0
- package/src/routes/chromium/tests/scrape.spec.ts +414 -0
- package/src/routes/chromium/tests/screenshot.spec.ts +387 -0
- package/src/routes/chromium/tests/websocket.spec.ts +407 -0
- package/src/routes/chromium/utils/function/client.ts +99 -0
- package/src/routes/chromium/utils/function/handler.ts +172 -0
- package/src/routes/chromium/utils/performance/child.ts +38 -0
- package/src/routes/chromium/utils/performance/main.ts +90 -0
- package/src/routes/chromium/utils/performance/types.ts +24 -0
- package/src/routes/chromium/ws/browser.ts +31 -0
- package/src/routes/chromium/ws/cdp-chromium.ts +31 -0
- package/src/routes/chromium/ws/page.ts +31 -0
- package/src/routes/chromium/ws/playwright-chromium.ts +44 -0
- package/src/routes/firefox/tests/websocket.spec.ts +146 -0
- package/src/routes/firefox/ws/playwright-firefox.ts +44 -0
- package/src/routes/management/http/config-get.ts +82 -0
- package/src/routes/management/http/metrics-get.ts +43 -0
- package/src/routes/management/http/metrics-total-get.ts +89 -0
- package/src/routes/management/http/sessions-get.ts +39 -0
- package/src/routes/management/http/static-get.ts +109 -0
- package/src/routes/management/tests/management.spec.ts +71 -0
- package/src/routes/webkit/tests/websocket.spec.ts +146 -0
- package/src/routes/webkit/ws/playwright-webkit.ts +44 -0
- package/src/server.ts +609 -0
- package/src/shim.spec.ts +154 -0
- package/src/shim.ts +78 -0
- package/src/types.ts +470 -0
- package/src/utils.ts +787 -0
- package/src/webhooks.ts +50 -0
- package/static/docs/browserless-logo.png +0 -0
- package/static/docs/docs.js +2 -0
- package/static/docs/index.html +71 -0
- package/static/docs/swagger.json +4232 -0
- package/static/favicon-32x32.png +0 -0
- package/static/function/client.js +31623 -0
- package/static/function/index.html +12 -0
- package/tsconfig.json +31 -0
|
@@ -0,0 +1,1802 @@
|
|
|
1
|
+
/*******************************************************************************
|
|
2
|
+
|
|
3
|
+
uBlock Origin - a browser extension to block requests.
|
|
4
|
+
Copyright (C) 2014-2015 The uBlock Origin authors
|
|
5
|
+
Copyright (C) 2014-present Raymond Hill
|
|
6
|
+
|
|
7
|
+
This program is free software: you can redistribute it and/or modify
|
|
8
|
+
it under the terms of the GNU General Public License as published by
|
|
9
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
(at your option) any later version.
|
|
11
|
+
|
|
12
|
+
This program is distributed in the hope that it will be useful,
|
|
13
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
GNU General Public License for more details.
|
|
16
|
+
|
|
17
|
+
You should have received a copy of the GNU General Public License
|
|
18
|
+
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|
19
|
+
|
|
20
|
+
Home: https://github.com/gorhill/uBlock
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
// For background page
|
|
24
|
+
|
|
25
|
+
/* globals browser */
|
|
26
|
+
|
|
27
|
+
'use strict';
|
|
28
|
+
|
|
29
|
+
/******************************************************************************/
|
|
30
|
+
|
|
31
|
+
import webext from './webext.js';
|
|
32
|
+
import { ubolog } from './console.js';
|
|
33
|
+
|
|
34
|
+
/******************************************************************************/
|
|
35
|
+
|
|
36
|
+
const manifest = browser.runtime.getManifest();
|
|
37
|
+
|
|
38
|
+
vAPI.cantWebsocket =
|
|
39
|
+
browser.webRequest.ResourceType instanceof Object === false ||
|
|
40
|
+
browser.webRequest.ResourceType.WEBSOCKET !== 'websocket';
|
|
41
|
+
|
|
42
|
+
vAPI.canWASM = vAPI.webextFlavor.soup.has('chromium') === false;
|
|
43
|
+
if ( vAPI.canWASM === false ) {
|
|
44
|
+
const csp = manifest.content_security_policy;
|
|
45
|
+
vAPI.canWASM = csp !== undefined && csp.indexOf("'wasm-unsafe-eval'") !== -1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
vAPI.supportsUserStylesheets = vAPI.webextFlavor.soup.has('user_stylesheet');
|
|
49
|
+
|
|
50
|
+
/******************************************************************************/
|
|
51
|
+
|
|
52
|
+
vAPI.app = {
|
|
53
|
+
name: manifest.name.replace(/ dev\w+ build/, ''),
|
|
54
|
+
version: (( ) => {
|
|
55
|
+
let version = manifest.version;
|
|
56
|
+
const match = /(\d+\.\d+\.\d+)(?:\.(\d+))?/.exec(version);
|
|
57
|
+
if ( match && match[2] ) {
|
|
58
|
+
const v = parseInt(match[2], 10);
|
|
59
|
+
version = match[1] + (v < 100 ? 'b' + v : 'rc' + (v - 100));
|
|
60
|
+
}
|
|
61
|
+
return version;
|
|
62
|
+
})(),
|
|
63
|
+
|
|
64
|
+
intFromVersion: function(s) {
|
|
65
|
+
const parts = s.match(/(?:^|\.|b|rc)\d+/g);
|
|
66
|
+
if ( parts === null ) { return 0; }
|
|
67
|
+
let vint = 0;
|
|
68
|
+
for ( let i = 0; i < 4; i++ ) {
|
|
69
|
+
const pstr = parts[i] || '';
|
|
70
|
+
let pint;
|
|
71
|
+
if ( pstr === '' ) {
|
|
72
|
+
pint = 0;
|
|
73
|
+
} else if ( pstr.startsWith('.') || pstr.startsWith('b') ) {
|
|
74
|
+
pint = parseInt(pstr.slice(1), 10);
|
|
75
|
+
} else if ( pstr.startsWith('rc') ) {
|
|
76
|
+
pint = parseInt(pstr.slice(2), 10) + 100;
|
|
77
|
+
} else {
|
|
78
|
+
pint = parseInt(pstr, 10);
|
|
79
|
+
}
|
|
80
|
+
vint = vint * 1000 + pint;
|
|
81
|
+
}
|
|
82
|
+
return vint;
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
restart: function() {
|
|
86
|
+
browser.runtime.reload();
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/******************************************************************************/
|
|
91
|
+
/******************************************************************************/
|
|
92
|
+
|
|
93
|
+
vAPI.storage = {
|
|
94
|
+
get(...args) {
|
|
95
|
+
return webext.storage.local.get(...args).catch(reason => {
|
|
96
|
+
console.log(reason);
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
set(...args) {
|
|
100
|
+
return webext.storage.local.set(...args).catch(reason => {
|
|
101
|
+
console.log(reason);
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
remove(...args) {
|
|
105
|
+
return webext.storage.local.remove(...args).catch(reason => {
|
|
106
|
+
console.log(reason);
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
clear(...args) {
|
|
110
|
+
return webext.storage.local.clear(...args).catch(reason => {
|
|
111
|
+
console.log(reason);
|
|
112
|
+
});
|
|
113
|
+
},
|
|
114
|
+
QUOTA_BYTES: browser.storage.local.QUOTA_BYTES,
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// Not all platforms support getBytesInUse
|
|
118
|
+
if ( webext.storage.local.getBytesInUse instanceof Function ) {
|
|
119
|
+
vAPI.storage.getBytesInUse = function(...args) {
|
|
120
|
+
return webext.storage.local.getBytesInUse(...args).catch(reason => {
|
|
121
|
+
console.log(reason);
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/******************************************************************************/
|
|
127
|
+
/******************************************************************************/
|
|
128
|
+
|
|
129
|
+
// https://github.com/gorhill/uMatrix/issues/234
|
|
130
|
+
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/privacy/network
|
|
131
|
+
|
|
132
|
+
// https://github.com/gorhill/uBlock/issues/2048
|
|
133
|
+
// Do not mess up with existing settings if not assigning them stricter
|
|
134
|
+
// values.
|
|
135
|
+
|
|
136
|
+
vAPI.browserSettings = (( ) => {
|
|
137
|
+
// Not all platforms support `browser.privacy`.
|
|
138
|
+
const bp = webext.privacy;
|
|
139
|
+
if ( bp instanceof Object === false ) { return; }
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
// https://github.com/uBlockOrigin/uBlock-issues/issues/1723#issuecomment-919913361
|
|
143
|
+
canLeakLocalIPAddresses:
|
|
144
|
+
vAPI.webextFlavor.soup.has('firefox') &&
|
|
145
|
+
vAPI.webextFlavor.soup.has('mobile'),
|
|
146
|
+
|
|
147
|
+
set: function(details) {
|
|
148
|
+
for ( const setting in details ) {
|
|
149
|
+
if ( details.hasOwnProperty(setting) === false ) { continue; }
|
|
150
|
+
switch ( setting ) {
|
|
151
|
+
case 'prefetching':
|
|
152
|
+
const enabled = !!details[setting];
|
|
153
|
+
if ( enabled ) {
|
|
154
|
+
bp.network.networkPredictionEnabled.clear({
|
|
155
|
+
scope: 'regular',
|
|
156
|
+
});
|
|
157
|
+
} else {
|
|
158
|
+
bp.network.networkPredictionEnabled.set({
|
|
159
|
+
value: false,
|
|
160
|
+
scope: 'regular',
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
if ( vAPI.prefetching instanceof Function ) {
|
|
164
|
+
vAPI.prefetching(enabled);
|
|
165
|
+
}
|
|
166
|
+
break;
|
|
167
|
+
|
|
168
|
+
case 'hyperlinkAuditing':
|
|
169
|
+
if ( !!details[setting] ) {
|
|
170
|
+
bp.websites.hyperlinkAuditingEnabled.clear({
|
|
171
|
+
scope: 'regular',
|
|
172
|
+
});
|
|
173
|
+
} else {
|
|
174
|
+
bp.websites.hyperlinkAuditingEnabled.set({
|
|
175
|
+
value: false,
|
|
176
|
+
scope: 'regular',
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
break;
|
|
180
|
+
|
|
181
|
+
case 'webrtcIPAddress': {
|
|
182
|
+
// https://github.com/uBlockOrigin/uBlock-issues/issues/1928
|
|
183
|
+
// https://www.reddit.com/r/uBlockOrigin/comments/sl7p74/
|
|
184
|
+
// Hypothetical: some browsers _think_ uBO is still using
|
|
185
|
+
// the setting possibly based on cached state from the
|
|
186
|
+
// past, and making an explicit API call that uBO is not
|
|
187
|
+
// using the setting appears to solve those unexpected
|
|
188
|
+
// reported occurrences of uBO interfering despite never
|
|
189
|
+
// using the API.
|
|
190
|
+
const mustEnable = !details[setting];
|
|
191
|
+
if ( this.canLeakLocalIPAddresses === false ) {
|
|
192
|
+
if ( mustEnable && vAPI.webextFlavor.soup.has('chromium') ) {
|
|
193
|
+
bp.network.webRTCIPHandlingPolicy.clear({
|
|
194
|
+
scope: 'regular',
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
if ( mustEnable ) {
|
|
200
|
+
bp.network.webRTCIPHandlingPolicy.set({
|
|
201
|
+
value: 'default_public_interface_only',
|
|
202
|
+
scope: 'regular'
|
|
203
|
+
});
|
|
204
|
+
} else {
|
|
205
|
+
bp.network.webRTCIPHandlingPolicy.clear({
|
|
206
|
+
scope: 'regular',
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
default:
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
})();
|
|
218
|
+
|
|
219
|
+
/******************************************************************************/
|
|
220
|
+
/******************************************************************************/
|
|
221
|
+
|
|
222
|
+
vAPI.isBehindTheSceneTabId = function(tabId) {
|
|
223
|
+
return tabId < 0;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
vAPI.unsetTabId = 0;
|
|
227
|
+
vAPI.noTabId = -1; // definitely not any existing tab
|
|
228
|
+
|
|
229
|
+
// To ensure we always use a good tab id
|
|
230
|
+
const toTabId = function(tabId) {
|
|
231
|
+
return typeof tabId === 'number' && isNaN(tabId) === false
|
|
232
|
+
? tabId
|
|
233
|
+
: 0;
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/webNavigation
|
|
237
|
+
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs
|
|
238
|
+
|
|
239
|
+
vAPI.Tabs = class {
|
|
240
|
+
constructor() {
|
|
241
|
+
browser.webNavigation.onCreatedNavigationTarget.addListener(details => {
|
|
242
|
+
this.onCreatedNavigationTargetHandler(details);
|
|
243
|
+
});
|
|
244
|
+
browser.webNavigation.onCommitted.addListener(details => {
|
|
245
|
+
const { frameId, tabId } = details;
|
|
246
|
+
if ( frameId === 0 && tabId > 0 && details.transitionType === 'reload' ) {
|
|
247
|
+
if ( vAPI.net && vAPI.net.hasUnprocessedRequest(tabId) ) {
|
|
248
|
+
vAPI.net.removeUnprocessedRequest(tabId);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
this.onCommittedHandler(details);
|
|
252
|
+
});
|
|
253
|
+
browser.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
|
254
|
+
this.onUpdatedHandler(tabId, changeInfo, tab);
|
|
255
|
+
});
|
|
256
|
+
browser.tabs.onActivated.addListener(details => {
|
|
257
|
+
this.onActivated(details);
|
|
258
|
+
});
|
|
259
|
+
// https://github.com/uBlockOrigin/uBlock-issues/issues/151
|
|
260
|
+
// https://github.com/uBlockOrigin/uBlock-issues/issues/680#issuecomment-515215220
|
|
261
|
+
if ( browser.windows instanceof Object ) {
|
|
262
|
+
browser.windows.onFocusChanged.addListener(windowId => {
|
|
263
|
+
this.onFocusChangedHandler(windowId);
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
browser.tabs.onRemoved.addListener((tabId, details) => {
|
|
267
|
+
if ( vAPI.net && vAPI.net.hasUnprocessedRequest(tabId) ) {
|
|
268
|
+
vAPI.net.removeUnprocessedRequest(tabId);
|
|
269
|
+
}
|
|
270
|
+
this.onRemovedHandler(tabId, details);
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
async executeScript() {
|
|
275
|
+
let result;
|
|
276
|
+
try {
|
|
277
|
+
result = await webext.tabs.executeScript(...arguments);
|
|
278
|
+
}
|
|
279
|
+
catch(reason) {
|
|
280
|
+
}
|
|
281
|
+
return Array.isArray(result) ? result : [];
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
async get(tabId) {
|
|
285
|
+
if ( tabId === null ) {
|
|
286
|
+
return this.getCurrent();
|
|
287
|
+
}
|
|
288
|
+
if ( tabId <= 0 ) { return null; }
|
|
289
|
+
let tab;
|
|
290
|
+
try {
|
|
291
|
+
tab = await webext.tabs.get(tabId);
|
|
292
|
+
}
|
|
293
|
+
catch(reason) {
|
|
294
|
+
}
|
|
295
|
+
return tab instanceof Object ? tab : null;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async getCurrent() {
|
|
299
|
+
const tabs = await this.query({ active: true, currentWindow: true });
|
|
300
|
+
return tabs.length !== 0 ? tabs[0] : null;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
async insertCSS(tabId, details) {
|
|
304
|
+
if ( vAPI.supportsUserStylesheets ) {
|
|
305
|
+
details.cssOrigin = 'user';
|
|
306
|
+
}
|
|
307
|
+
try {
|
|
308
|
+
await webext.tabs.insertCSS(...arguments);
|
|
309
|
+
}
|
|
310
|
+
catch(reason) {
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
async query(queryInfo) {
|
|
315
|
+
let tabs;
|
|
316
|
+
try {
|
|
317
|
+
tabs = await webext.tabs.query(queryInfo);
|
|
318
|
+
}
|
|
319
|
+
catch(reason) {
|
|
320
|
+
}
|
|
321
|
+
return Array.isArray(tabs) ? tabs : [];
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
async removeCSS(tabId, details) {
|
|
325
|
+
if ( vAPI.supportsUserStylesheets ) {
|
|
326
|
+
details.cssOrigin = 'user';
|
|
327
|
+
}
|
|
328
|
+
try {
|
|
329
|
+
await webext.tabs.removeCSS(...arguments);
|
|
330
|
+
}
|
|
331
|
+
catch(reason) {
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Properties of the details object:
|
|
336
|
+
// - url: 'URL', => the address that will be opened
|
|
337
|
+
// - index: -1, => undefined: end of the list, -1: following tab,
|
|
338
|
+
// or after index
|
|
339
|
+
// - active: false, => opens the tab... in background: true,
|
|
340
|
+
// foreground: undefined
|
|
341
|
+
// - popup: 'popup' => open in a new window
|
|
342
|
+
|
|
343
|
+
async create(url, details) {
|
|
344
|
+
if ( details.active === undefined ) {
|
|
345
|
+
details.active = true;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const subWrapper = async ( ) => {
|
|
349
|
+
const updateDetails = {
|
|
350
|
+
url: url,
|
|
351
|
+
active: !!details.active
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
// Opening a tab from incognito window won't focus the window
|
|
355
|
+
// in which the tab was opened
|
|
356
|
+
const focusWindow = tab => {
|
|
357
|
+
if ( tab.active && vAPI.windows instanceof Object ) {
|
|
358
|
+
vAPI.windows.update(tab.windowId, { focused: true });
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
if ( !details.tabId ) {
|
|
363
|
+
if ( details.index !== undefined ) {
|
|
364
|
+
updateDetails.index = details.index;
|
|
365
|
+
}
|
|
366
|
+
browser.tabs.create(updateDetails, focusWindow);
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// update doesn't accept index, must use move
|
|
371
|
+
const tab = await vAPI.tabs.update(
|
|
372
|
+
toTabId(details.tabId),
|
|
373
|
+
updateDetails
|
|
374
|
+
);
|
|
375
|
+
// if the tab doesn't exist
|
|
376
|
+
if ( tab === null ) {
|
|
377
|
+
browser.tabs.create(updateDetails, focusWindow);
|
|
378
|
+
} else if ( details.index !== undefined ) {
|
|
379
|
+
browser.tabs.move(tab.id, { index: details.index });
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
// Open in a standalone window
|
|
384
|
+
//
|
|
385
|
+
// https://github.com/uBlockOrigin/uBlock-issues/issues/168#issuecomment-413038191
|
|
386
|
+
// Not all platforms support vAPI.windows.
|
|
387
|
+
//
|
|
388
|
+
// For some reasons, some platforms do not honor the left,top
|
|
389
|
+
// position when specified. I found that further calling
|
|
390
|
+
// windows.update again with the same position _may_ help.
|
|
391
|
+
if ( details.popup !== undefined && vAPI.windows instanceof Object ) {
|
|
392
|
+
const createDetails = {
|
|
393
|
+
url: details.url,
|
|
394
|
+
type: details.popup,
|
|
395
|
+
};
|
|
396
|
+
if ( details.box instanceof Object ) {
|
|
397
|
+
Object.assign(createDetails, details.box);
|
|
398
|
+
}
|
|
399
|
+
const win = await vAPI.windows.create(createDetails);
|
|
400
|
+
if ( win === null ) { return; }
|
|
401
|
+
if ( details.box instanceof Object === false ) { return; }
|
|
402
|
+
if (
|
|
403
|
+
win.left === details.box.left &&
|
|
404
|
+
win.top === details.box.top
|
|
405
|
+
) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
vAPI.windows.update(win.id, {
|
|
409
|
+
left: details.box.left,
|
|
410
|
+
top: details.box.top
|
|
411
|
+
});
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if ( details.index !== -1 ) {
|
|
416
|
+
subWrapper();
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
const tab = await vAPI.tabs.getCurrent();
|
|
421
|
+
if ( tab !== null ) {
|
|
422
|
+
details.index = tab.index + 1;
|
|
423
|
+
} else {
|
|
424
|
+
details.index = undefined;
|
|
425
|
+
}
|
|
426
|
+
subWrapper();
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// Properties of the details object:
|
|
430
|
+
// - url: 'URL', => the address that will be opened
|
|
431
|
+
// - tabId: 1, => the tab is used if set, instead of creating a new one
|
|
432
|
+
// - index: -1, => undefined: end of the list, -1: following tab, or
|
|
433
|
+
// after index
|
|
434
|
+
// - active: false, => opens the tab in background - true and undefined:
|
|
435
|
+
// foreground
|
|
436
|
+
// - select: true, => if a tab is already opened with that url, then select
|
|
437
|
+
// it instead of opening a new one
|
|
438
|
+
// - popup: true => open in a new window
|
|
439
|
+
|
|
440
|
+
async open(details) {
|
|
441
|
+
let targetURL = details.url;
|
|
442
|
+
if ( typeof targetURL !== 'string' || targetURL === '' ) {
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// extension pages
|
|
447
|
+
if ( /^[\w-]{2,}:/.test(targetURL) !== true ) {
|
|
448
|
+
targetURL = vAPI.getURL(targetURL);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
if ( !details.select ) {
|
|
452
|
+
this.create(targetURL, details);
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/query#Parameters
|
|
457
|
+
// "Note that fragment identifiers are not matched."
|
|
458
|
+
// Fragment identifiers ARE matched -- we need to remove the fragment.
|
|
459
|
+
const pos = targetURL.indexOf('#');
|
|
460
|
+
const targetURLWithoutHash = pos === -1
|
|
461
|
+
? targetURL
|
|
462
|
+
: targetURL.slice(0, pos);
|
|
463
|
+
|
|
464
|
+
const tabs = await vAPI.tabs.query({ url: targetURLWithoutHash });
|
|
465
|
+
if ( tabs.length === 0 ) {
|
|
466
|
+
this.create(targetURL, details);
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
let tab = tabs[0];
|
|
470
|
+
const updateDetails = { active: true };
|
|
471
|
+
// https://github.com/uBlockOrigin/uBlock-issues/issues/592
|
|
472
|
+
if ( tab.url.startsWith(targetURL) === false ) {
|
|
473
|
+
updateDetails.url = targetURL;
|
|
474
|
+
}
|
|
475
|
+
tab = await vAPI.tabs.update(tab.id, updateDetails);
|
|
476
|
+
if ( vAPI.windows instanceof Object === false ) { return; }
|
|
477
|
+
vAPI.windows.update(tab.windowId, { focused: true });
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
async update() {
|
|
481
|
+
let tab;
|
|
482
|
+
try {
|
|
483
|
+
tab = await webext.tabs.update(...arguments);
|
|
484
|
+
}
|
|
485
|
+
catch (reason) {
|
|
486
|
+
}
|
|
487
|
+
return tab instanceof Object ? tab : null;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// Replace the URL of a tab. Noop if the tab does not exist.
|
|
491
|
+
replace(tabId, url) {
|
|
492
|
+
tabId = toTabId(tabId);
|
|
493
|
+
if ( tabId === 0 ) { return; }
|
|
494
|
+
|
|
495
|
+
let targetURL = url;
|
|
496
|
+
|
|
497
|
+
// extension pages
|
|
498
|
+
if ( /^[\w-]{2,}:/.test(targetURL) !== true ) {
|
|
499
|
+
targetURL = vAPI.getURL(targetURL);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
vAPI.tabs.update(tabId, { url: targetURL });
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
async remove(tabId) {
|
|
506
|
+
tabId = toTabId(tabId);
|
|
507
|
+
if ( tabId === 0 ) { return; }
|
|
508
|
+
try {
|
|
509
|
+
await webext.tabs.remove(tabId);
|
|
510
|
+
}
|
|
511
|
+
catch (reason) {
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
async reload(tabId, bypassCache = false) {
|
|
516
|
+
tabId = toTabId(tabId);
|
|
517
|
+
if ( tabId === 0 ) { return; }
|
|
518
|
+
try {
|
|
519
|
+
await webext.tabs.reload(
|
|
520
|
+
tabId,
|
|
521
|
+
{ bypassCache: bypassCache === true }
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
catch (reason) {
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
async select(tabId) {
|
|
529
|
+
tabId = toTabId(tabId);
|
|
530
|
+
if ( tabId === 0 ) { return; }
|
|
531
|
+
const tab = await vAPI.tabs.update(tabId, { active: true });
|
|
532
|
+
if ( tab === null ) { return; }
|
|
533
|
+
if ( vAPI.windows instanceof Object === false ) { return; }
|
|
534
|
+
vAPI.windows.update(tab.windowId, { focused: true });
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
// https://forums.lanik.us/viewtopic.php?f=62&t=32826
|
|
538
|
+
// Chromium-based browsers: sanitize target URL. I've seen data: URI with
|
|
539
|
+
// newline characters in standard fields, possibly as a way of evading
|
|
540
|
+
// filters. As per spec, there should be no whitespaces in a data: URI's
|
|
541
|
+
// standard fields.
|
|
542
|
+
|
|
543
|
+
sanitizeURL(url) {
|
|
544
|
+
if ( url.startsWith('data:') === false ) { return url; }
|
|
545
|
+
const pos = url.indexOf(',');
|
|
546
|
+
if ( pos === -1 ) { return url; }
|
|
547
|
+
const s = url.slice(0, pos);
|
|
548
|
+
if ( s.search(/\s/) === -1 ) { return url; }
|
|
549
|
+
return s.replace(/\s+/, '') + url.slice(pos);
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
onCreatedNavigationTargetHandler(details) {
|
|
553
|
+
if ( typeof details.url !== 'string' ) {
|
|
554
|
+
details.url = '';
|
|
555
|
+
}
|
|
556
|
+
if ( /^https?:\/\//.test(details.url) === false ) {
|
|
557
|
+
details.frameId = 0;
|
|
558
|
+
details.url = this.sanitizeURL(details.url);
|
|
559
|
+
this.onNavigation(details);
|
|
560
|
+
}
|
|
561
|
+
this.onCreated(details);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
onCommittedHandler(details) {
|
|
565
|
+
details.url = this.sanitizeURL(details.url);
|
|
566
|
+
this.onNavigation(details);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
onUpdatedHandler(tabId, changeInfo, tab) {
|
|
570
|
+
// Ignore uninteresting update events
|
|
571
|
+
const { status = '', title = '', url = '' } = changeInfo;
|
|
572
|
+
if ( status === '' && title === '' && url === '' ) { return; }
|
|
573
|
+
// https://github.com/gorhill/uBlock/issues/3073
|
|
574
|
+
// Fall back to `tab.url` when `changeInfo.url` is not set.
|
|
575
|
+
if ( url === '' ) {
|
|
576
|
+
changeInfo.url = tab && tab.url;
|
|
577
|
+
}
|
|
578
|
+
if ( changeInfo.url ) {
|
|
579
|
+
changeInfo.url = this.sanitizeURL(changeInfo.url);
|
|
580
|
+
}
|
|
581
|
+
this.onUpdated(tabId, changeInfo, tab);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
onRemovedHandler(tabId, details) {
|
|
585
|
+
this.onClosed(tabId, details);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
onFocusChangedHandler(windowId) {
|
|
589
|
+
if ( windowId === browser.windows.WINDOW_ID_NONE ) { return; }
|
|
590
|
+
vAPI.tabs.query({ active: true, windowId }).then(tabs => {
|
|
591
|
+
if ( tabs.length === 0 ) { return; }
|
|
592
|
+
const tab = tabs[0];
|
|
593
|
+
this.onActivated({ tabId: tab.id, windowId: tab.windowId });
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
onActivated(/* details */) {
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
onClosed(/* tabId, details */) {
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
onCreated(/* details */) {
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
onNavigation(/* details */) {
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
onUpdated(/* tabId, changeInfo, tab */) {
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
|
|
613
|
+
/******************************************************************************/
|
|
614
|
+
/******************************************************************************/
|
|
615
|
+
|
|
616
|
+
if ( webext.windows instanceof Object ) {
|
|
617
|
+
vAPI.windows = {
|
|
618
|
+
get: async function() {
|
|
619
|
+
let win;
|
|
620
|
+
try {
|
|
621
|
+
win = await webext.windows.get(...arguments);
|
|
622
|
+
}
|
|
623
|
+
catch (reason) {
|
|
624
|
+
}
|
|
625
|
+
return win instanceof Object ? win : null;
|
|
626
|
+
},
|
|
627
|
+
create: async function() {
|
|
628
|
+
let win;
|
|
629
|
+
try {
|
|
630
|
+
win = await webext.windows.create(...arguments);
|
|
631
|
+
}
|
|
632
|
+
catch (reason) {
|
|
633
|
+
}
|
|
634
|
+
return win instanceof Object ? win : null;
|
|
635
|
+
},
|
|
636
|
+
update: async function() {
|
|
637
|
+
let win;
|
|
638
|
+
try {
|
|
639
|
+
win = await webext.windows.update(...arguments);
|
|
640
|
+
}
|
|
641
|
+
catch (reason) {
|
|
642
|
+
}
|
|
643
|
+
return win instanceof Object ? win : null;
|
|
644
|
+
},
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
/******************************************************************************/
|
|
649
|
+
/******************************************************************************/
|
|
650
|
+
|
|
651
|
+
if ( webext.browserAction instanceof Object ) {
|
|
652
|
+
vAPI.browserAction = {
|
|
653
|
+
setTitle: async function() {
|
|
654
|
+
try {
|
|
655
|
+
await webext.browserAction.setTitle(...arguments);
|
|
656
|
+
}
|
|
657
|
+
catch (reason) {
|
|
658
|
+
}
|
|
659
|
+
},
|
|
660
|
+
};
|
|
661
|
+
// Not supported on Firefox for Android
|
|
662
|
+
if ( webext.browserAction.setIcon ) {
|
|
663
|
+
vAPI.browserAction.setBadgeTextColor = async function() {
|
|
664
|
+
try {
|
|
665
|
+
await webext.browserAction.setBadgeTextColor(...arguments);
|
|
666
|
+
}
|
|
667
|
+
catch (reason) {
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
vAPI.browserAction.setBadgeBackgroundColor = async function() {
|
|
671
|
+
try {
|
|
672
|
+
await webext.browserAction.setBadgeBackgroundColor(...arguments);
|
|
673
|
+
}
|
|
674
|
+
catch (reason) {
|
|
675
|
+
}
|
|
676
|
+
};
|
|
677
|
+
vAPI.browserAction.setBadgeText = async function() {
|
|
678
|
+
try {
|
|
679
|
+
await webext.browserAction.setBadgeText(...arguments);
|
|
680
|
+
}
|
|
681
|
+
catch (reason) {
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
vAPI.browserAction.setIcon = async function() {
|
|
685
|
+
try {
|
|
686
|
+
await webext.browserAction.setIcon(...arguments);
|
|
687
|
+
}
|
|
688
|
+
catch (reason) {
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/******************************************************************************/
|
|
695
|
+
/******************************************************************************/
|
|
696
|
+
|
|
697
|
+
// Must read: https://code.google.com/p/chromium/issues/detail?id=410868#c8
|
|
698
|
+
|
|
699
|
+
// https://github.com/chrisaljoudi/uBlock/issues/19
|
|
700
|
+
// https://github.com/chrisaljoudi/uBlock/issues/207
|
|
701
|
+
// Since we may be called asynchronously, the tab id may not exist
|
|
702
|
+
// anymore, so this ensures it does still exist.
|
|
703
|
+
|
|
704
|
+
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/browserAction#Browser_compatibility
|
|
705
|
+
// Firefox for Android does no support browser.browserAction.setIcon().
|
|
706
|
+
// Performance: use ImageData for platforms supporting it.
|
|
707
|
+
|
|
708
|
+
// https://github.com/uBlockOrigin/uBlock-issues/issues/32
|
|
709
|
+
// Ensure ImageData for toolbar icon is valid before use.
|
|
710
|
+
|
|
711
|
+
{
|
|
712
|
+
const browserAction = vAPI.browserAction;
|
|
713
|
+
const titleTemplate = `${browser.runtime.getManifest().browser_action.default_title} ({badge})`;
|
|
714
|
+
const icons = [
|
|
715
|
+
{ path: {
|
|
716
|
+
'16': 'img/icon_16-off.png',
|
|
717
|
+
'32': 'img/icon_32-off.png',
|
|
718
|
+
'64': 'img/icon_64-off.png',
|
|
719
|
+
} },
|
|
720
|
+
{ path: {
|
|
721
|
+
'16': 'img/icon_16.png',
|
|
722
|
+
'32': 'img/icon_32.png',
|
|
723
|
+
'64': 'img/icon_64.png',
|
|
724
|
+
} },
|
|
725
|
+
];
|
|
726
|
+
|
|
727
|
+
(( ) => {
|
|
728
|
+
if ( browserAction.setIcon === undefined ) { return; }
|
|
729
|
+
|
|
730
|
+
// The global badge text and background color.
|
|
731
|
+
if ( browserAction.setBadgeBackgroundColor !== undefined ) {
|
|
732
|
+
browserAction.setBadgeBackgroundColor({ color: '#666666' });
|
|
733
|
+
}
|
|
734
|
+
if ( browserAction.setBadgeTextColor !== undefined ) {
|
|
735
|
+
browserAction.setBadgeTextColor({ color: '#FFFFFF' });
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
// As of 2018-05, benchmarks show that only Chromium benefits for sure
|
|
739
|
+
// from using ImageData.
|
|
740
|
+
//
|
|
741
|
+
// Chromium creates a new ImageData instance every call to setIcon
|
|
742
|
+
// with paths:
|
|
743
|
+
// https://cs.chromium.org/chromium/src/extensions/renderer/resources/set_icon.js?l=56&rcl=99be185c25738437ecfa0dafba72a26114196631
|
|
744
|
+
//
|
|
745
|
+
// Firefox uses an internal cache for each setIcon's paths:
|
|
746
|
+
// https://searchfox.org/mozilla-central/rev/5ff2d7683078c96e4b11b8a13674daded935aa44/browser/components/extensions/parent/ext-browserAction.js#631
|
|
747
|
+
if ( vAPI.webextFlavor.soup.has('chromium') === false ) { return; }
|
|
748
|
+
|
|
749
|
+
const imgs = [];
|
|
750
|
+
for ( let i = 0; i < icons.length; i++ ) {
|
|
751
|
+
for ( const key of Object.keys(icons[i].path) ) {
|
|
752
|
+
if ( parseInt(key, 10) >= 64 ) { continue; }
|
|
753
|
+
imgs.push({ i: i, p: key, cached: false });
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
// https://github.com/uBlockOrigin/uBlock-issues/issues/296
|
|
758
|
+
const safeGetImageData = function(ctx, w, h) {
|
|
759
|
+
let data;
|
|
760
|
+
try {
|
|
761
|
+
data = ctx.getImageData(0, 0, w, h);
|
|
762
|
+
} catch(ex) {
|
|
763
|
+
}
|
|
764
|
+
return data;
|
|
765
|
+
};
|
|
766
|
+
|
|
767
|
+
const onLoaded = function() {
|
|
768
|
+
for ( const img of imgs ) {
|
|
769
|
+
if ( img.r.complete === false ) { return; }
|
|
770
|
+
}
|
|
771
|
+
const ctx = document.createElement('canvas')
|
|
772
|
+
.getContext('2d', { willReadFrequently: true });
|
|
773
|
+
const iconData = [ null, null ];
|
|
774
|
+
for ( const img of imgs ) {
|
|
775
|
+
if ( img.cached ) { continue; }
|
|
776
|
+
const w = img.r.naturalWidth, h = img.r.naturalHeight;
|
|
777
|
+
ctx.width = w; ctx.height = h;
|
|
778
|
+
ctx.clearRect(0, 0, w, h);
|
|
779
|
+
ctx.drawImage(img.r, 0, 0);
|
|
780
|
+
if ( iconData[img.i] === null ) { iconData[img.i] = {}; }
|
|
781
|
+
const imgData = safeGetImageData(ctx, w, h);
|
|
782
|
+
if (
|
|
783
|
+
imgData instanceof Object === false ||
|
|
784
|
+
imgData.data instanceof Uint8ClampedArray === false ||
|
|
785
|
+
imgData.data[0] !== 0 ||
|
|
786
|
+
imgData.data[1] !== 0 ||
|
|
787
|
+
imgData.data[2] !== 0 ||
|
|
788
|
+
imgData.data[3] !== 0
|
|
789
|
+
) {
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
792
|
+
iconData[img.i][img.p] = imgData;
|
|
793
|
+
img.cached = true;
|
|
794
|
+
}
|
|
795
|
+
for ( let i = 0; i < iconData.length; i++ ) {
|
|
796
|
+
if ( iconData[i] ) {
|
|
797
|
+
icons[i] = { imageData: iconData[i] };
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
for ( const img of imgs ) {
|
|
802
|
+
img.r = new Image();
|
|
803
|
+
img.r.addEventListener('load', onLoaded, { once: true });
|
|
804
|
+
img.r.src = icons[img.i].path[img.p];
|
|
805
|
+
}
|
|
806
|
+
})();
|
|
807
|
+
|
|
808
|
+
// parts: bit 0 = icon
|
|
809
|
+
// bit 1 = badge text
|
|
810
|
+
// bit 2 = badge color
|
|
811
|
+
// bit 3 = hide badge
|
|
812
|
+
|
|
813
|
+
vAPI.setIcon = async function(tabId, details) {
|
|
814
|
+
tabId = toTabId(tabId);
|
|
815
|
+
if ( tabId === 0 ) { return; }
|
|
816
|
+
|
|
817
|
+
const tab = await vAPI.tabs.get(tabId);
|
|
818
|
+
if ( tab === null ) { return; }
|
|
819
|
+
|
|
820
|
+
const hasUnprocessedRequest = vAPI.net && vAPI.net.hasUnprocessedRequest(tabId);
|
|
821
|
+
const { parts, state } = details;
|
|
822
|
+
const { badge, color } = hasUnprocessedRequest
|
|
823
|
+
? { badge: '!', color: '#FC0' }
|
|
824
|
+
: details;
|
|
825
|
+
|
|
826
|
+
if ( browserAction.setIcon !== undefined ) {
|
|
827
|
+
if ( parts === undefined || (parts & 0b0001) !== 0 ) {
|
|
828
|
+
browserAction.setIcon(
|
|
829
|
+
Object.assign({ tabId: tab.id }, icons[state])
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
if ( (parts & 0b0010) !== 0 ) {
|
|
833
|
+
browserAction.setBadgeText({
|
|
834
|
+
tabId: tab.id,
|
|
835
|
+
text: (parts & 0b1000) === 0 ? badge : ''
|
|
836
|
+
});
|
|
837
|
+
}
|
|
838
|
+
if ( (parts & 0b0100) !== 0 ) {
|
|
839
|
+
browserAction.setBadgeBackgroundColor({ tabId: tab.id, color });
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
// Insert the badge text in the title if:
|
|
844
|
+
// - the platform does not support browserAction.setIcon(); OR
|
|
845
|
+
// - the rendering of the badge is disabled
|
|
846
|
+
if ( browserAction.setTitle !== undefined ) {
|
|
847
|
+
const title = titleTemplate.replace('{badge}',
|
|
848
|
+
state === 1 ? (badge !== '' ? badge : '0') : 'off'
|
|
849
|
+
);
|
|
850
|
+
browserAction.setTitle({ tabId: tab.id, title });
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
if ( vAPI.contextMenu instanceof Object ) {
|
|
854
|
+
vAPI.contextMenu.onMustUpdate(tabId);
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
|
|
858
|
+
vAPI.setDefaultIcon = function(flavor, text) {
|
|
859
|
+
if ( browserAction.setIcon === undefined ) { return; }
|
|
860
|
+
browserAction.setIcon({
|
|
861
|
+
path: {
|
|
862
|
+
'16': `img/icon_16${flavor}.png`,
|
|
863
|
+
'32': `img/icon_32${flavor}.png`,
|
|
864
|
+
'64': `img/icon_64${flavor}.png`,
|
|
865
|
+
}
|
|
866
|
+
});
|
|
867
|
+
browserAction.setBadgeText({ text });
|
|
868
|
+
browserAction.setBadgeBackgroundColor({
|
|
869
|
+
color: text === '!' ? '#FC0' : '#666'
|
|
870
|
+
});
|
|
871
|
+
};
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
browser.browserAction.onClicked.addListener(function(tab) {
|
|
875
|
+
vAPI.tabs.open({
|
|
876
|
+
select: true,
|
|
877
|
+
url: `popup-fenix.html?tabId=${tab.id}&intab=1`,
|
|
878
|
+
});
|
|
879
|
+
});
|
|
880
|
+
|
|
881
|
+
/******************************************************************************/
|
|
882
|
+
/******************************************************************************/
|
|
883
|
+
|
|
884
|
+
// https://github.com/uBlockOrigin/uBlock-issues/issues/710
|
|
885
|
+
// uBO uses only ports to communicate with its auxiliary pages and
|
|
886
|
+
// content scripts. Whether a message can trigger a privileged operation is
|
|
887
|
+
// decided based on whether the port from which a message is received is
|
|
888
|
+
// privileged, which is a status evaluated once, at port connection time.
|
|
889
|
+
//
|
|
890
|
+
// https://github.com/uBlockOrigin/uBlock-issues/issues/1992
|
|
891
|
+
// If present, use MessageSender.origin to determine whether the port is
|
|
892
|
+
// from a privileged page, otherwise use MessageSender.url.
|
|
893
|
+
// MessageSender.origin is more reliable as it is not spoofable by a
|
|
894
|
+
// compromised renderer.
|
|
895
|
+
|
|
896
|
+
vAPI.messaging = {
|
|
897
|
+
ports: new Map(),
|
|
898
|
+
listeners: new Map(),
|
|
899
|
+
defaultHandler: null,
|
|
900
|
+
PRIVILEGED_ORIGIN: vAPI.getURL('').slice(0, -1),
|
|
901
|
+
NOOPFUNC: function(){},
|
|
902
|
+
UNHANDLED: 'vAPI.messaging.notHandled',
|
|
903
|
+
|
|
904
|
+
listen: function(details) {
|
|
905
|
+
this.listeners.set(details.name, {
|
|
906
|
+
fn: details.listener,
|
|
907
|
+
privileged: details.privileged === true
|
|
908
|
+
});
|
|
909
|
+
},
|
|
910
|
+
|
|
911
|
+
onPortDisconnect: function(port) {
|
|
912
|
+
this.ports.delete(port.name);
|
|
913
|
+
},
|
|
914
|
+
|
|
915
|
+
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/runtime/Port
|
|
916
|
+
// port.sender is always present for onConnect() listeners.
|
|
917
|
+
onPortConnect: function(port) {
|
|
918
|
+
port.onDisconnect.addListener(port =>
|
|
919
|
+
this.onPortDisconnect(port)
|
|
920
|
+
);
|
|
921
|
+
port.onMessage.addListener((request, port) =>
|
|
922
|
+
this.onPortMessage(request, port)
|
|
923
|
+
);
|
|
924
|
+
const portDetails = { port };
|
|
925
|
+
const sender = port.sender;
|
|
926
|
+
const { origin, tab, url } = sender;
|
|
927
|
+
portDetails.frameId = sender.frameId;
|
|
928
|
+
portDetails.frameURL = url;
|
|
929
|
+
portDetails.privileged = origin !== undefined
|
|
930
|
+
? origin === this.PRIVILEGED_ORIGIN
|
|
931
|
+
: url.startsWith(this.PRIVILEGED_ORIGIN);
|
|
932
|
+
if ( tab ) {
|
|
933
|
+
portDetails.tabId = tab.id;
|
|
934
|
+
portDetails.tabURL = tab.url;
|
|
935
|
+
}
|
|
936
|
+
this.ports.set(port.name, portDetails);
|
|
937
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=1652925#c24
|
|
938
|
+
port.sender = undefined;
|
|
939
|
+
},
|
|
940
|
+
|
|
941
|
+
setup: function(defaultHandler) {
|
|
942
|
+
if ( this.defaultHandler !== null ) { return; }
|
|
943
|
+
|
|
944
|
+
if ( typeof defaultHandler !== 'function' ) {
|
|
945
|
+
defaultHandler = function() {
|
|
946
|
+
return this.UNHANDLED;
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
this.defaultHandler = defaultHandler;
|
|
950
|
+
|
|
951
|
+
browser.runtime.onConnect.addListener(
|
|
952
|
+
port => this.onPortConnect(port)
|
|
953
|
+
);
|
|
954
|
+
|
|
955
|
+
// https://bugzilla.mozilla.org/show_bug.cgi?id=1392067
|
|
956
|
+
// Workaround: manually remove ports matching removed tab.
|
|
957
|
+
if (
|
|
958
|
+
vAPI.webextFlavor.soup.has('firefox') &&
|
|
959
|
+
vAPI.webextFlavor.major < 61
|
|
960
|
+
) {
|
|
961
|
+
browser.tabs.onRemoved.addListener(tabId => {
|
|
962
|
+
for ( const { port, tabId: portTabId } of this.ports.values() ) {
|
|
963
|
+
if ( portTabId !== tabId ) { continue; }
|
|
964
|
+
this.onPortDisconnect(port);
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
},
|
|
969
|
+
|
|
970
|
+
broadcast: function(message) {
|
|
971
|
+
const messageWrapper = { broadcast: true, msg: message };
|
|
972
|
+
for ( const { port } of this.ports.values() ) {
|
|
973
|
+
try {
|
|
974
|
+
port.postMessage(messageWrapper);
|
|
975
|
+
} catch(ex) {
|
|
976
|
+
this.onPortDisconnect(port);
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
if ( this.defaultHandler ) {
|
|
980
|
+
this.defaultHandler(message, null, ( ) => { });
|
|
981
|
+
}
|
|
982
|
+
},
|
|
983
|
+
|
|
984
|
+
onFrameworkMessage: function(request, port, callback) {
|
|
985
|
+
const portDetails = this.ports.get(port.name) || {};
|
|
986
|
+
const tabId = portDetails.tabId;
|
|
987
|
+
const msg = request.msg;
|
|
988
|
+
switch ( msg.what ) {
|
|
989
|
+
case 'connectionAccepted':
|
|
990
|
+
case 'connectionRefused': {
|
|
991
|
+
const toPort = this.ports.get(msg.fromToken);
|
|
992
|
+
if ( toPort !== undefined ) {
|
|
993
|
+
msg.tabId = tabId;
|
|
994
|
+
toPort.port.postMessage(request);
|
|
995
|
+
} else {
|
|
996
|
+
msg.what = 'connectionBroken';
|
|
997
|
+
port.postMessage(request);
|
|
998
|
+
}
|
|
999
|
+
break;
|
|
1000
|
+
}
|
|
1001
|
+
case 'connectionRequested':
|
|
1002
|
+
msg.tabId = tabId;
|
|
1003
|
+
for ( const { port: toPort } of this.ports.values() ) {
|
|
1004
|
+
if ( toPort === port ) { continue; }
|
|
1005
|
+
try {
|
|
1006
|
+
toPort.postMessage(request);
|
|
1007
|
+
} catch (ex) {
|
|
1008
|
+
this.onPortDisconnect(toPort);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
break;
|
|
1012
|
+
case 'connectionBroken':
|
|
1013
|
+
case 'connectionCheck':
|
|
1014
|
+
case 'connectionMessage': {
|
|
1015
|
+
const toPort = this.ports.get(
|
|
1016
|
+
port.name === msg.fromToken ? msg.toToken : msg.fromToken
|
|
1017
|
+
);
|
|
1018
|
+
if ( toPort !== undefined ) {
|
|
1019
|
+
msg.tabId = tabId;
|
|
1020
|
+
toPort.port.postMessage(request);
|
|
1021
|
+
} else {
|
|
1022
|
+
msg.what = 'connectionBroken';
|
|
1023
|
+
port.postMessage(request);
|
|
1024
|
+
}
|
|
1025
|
+
break;
|
|
1026
|
+
}
|
|
1027
|
+
case 'extendClient':
|
|
1028
|
+
vAPI.tabs.executeScript(tabId, {
|
|
1029
|
+
file: '/js/vapi-client-extra.js',
|
|
1030
|
+
frameId: portDetails.frameId,
|
|
1031
|
+
}).then(( ) => {
|
|
1032
|
+
callback();
|
|
1033
|
+
});
|
|
1034
|
+
break;
|
|
1035
|
+
case 'localStorage': {
|
|
1036
|
+
if ( portDetails.privileged !== true ) { break; }
|
|
1037
|
+
const args = msg.args || [];
|
|
1038
|
+
vAPI.localStorage[msg.fn](...args).then(result => {
|
|
1039
|
+
callback(result);
|
|
1040
|
+
});
|
|
1041
|
+
break;
|
|
1042
|
+
}
|
|
1043
|
+
case 'userCSS':
|
|
1044
|
+
if ( tabId === undefined ) { break; }
|
|
1045
|
+
const promises = [];
|
|
1046
|
+
if ( msg.add ) {
|
|
1047
|
+
const details = {
|
|
1048
|
+
code: undefined,
|
|
1049
|
+
frameId: portDetails.frameId,
|
|
1050
|
+
matchAboutBlank: true,
|
|
1051
|
+
runAt: 'document_start',
|
|
1052
|
+
};
|
|
1053
|
+
for ( const cssText of msg.add ) {
|
|
1054
|
+
details.code = cssText;
|
|
1055
|
+
promises.push(vAPI.tabs.insertCSS(tabId, details));
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
if ( msg.remove ) {
|
|
1059
|
+
const details = {
|
|
1060
|
+
code: undefined,
|
|
1061
|
+
frameId: portDetails.frameId,
|
|
1062
|
+
matchAboutBlank: true,
|
|
1063
|
+
};
|
|
1064
|
+
for ( const cssText of msg.remove ) {
|
|
1065
|
+
details.code = cssText;
|
|
1066
|
+
promises.push(vAPI.tabs.removeCSS(tabId, details));
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
Promise.all(promises).then(( ) => {
|
|
1070
|
+
callback();
|
|
1071
|
+
});
|
|
1072
|
+
break;
|
|
1073
|
+
}
|
|
1074
|
+
},
|
|
1075
|
+
|
|
1076
|
+
// Use a wrapper to avoid closure and to allow reuse.
|
|
1077
|
+
CallbackWrapper: class {
|
|
1078
|
+
constructor(messaging, port, msgId) {
|
|
1079
|
+
this.messaging = messaging;
|
|
1080
|
+
this.callback = this.proxy.bind(this); // bind once
|
|
1081
|
+
this.init(port, msgId);
|
|
1082
|
+
}
|
|
1083
|
+
init(port, msgId) {
|
|
1084
|
+
this.port = port;
|
|
1085
|
+
this.msgId = msgId;
|
|
1086
|
+
return this;
|
|
1087
|
+
}
|
|
1088
|
+
proxy(response) {
|
|
1089
|
+
// https://github.com/chrisaljoudi/uBlock/issues/383
|
|
1090
|
+
try {
|
|
1091
|
+
this.port.postMessage({
|
|
1092
|
+
msgId: this.msgId,
|
|
1093
|
+
msg: response !== undefined ? response : null,
|
|
1094
|
+
});
|
|
1095
|
+
} catch (ex) {
|
|
1096
|
+
this.messaging.onPortDisconnect(this.port);
|
|
1097
|
+
}
|
|
1098
|
+
// Store for reuse
|
|
1099
|
+
this.port = null;
|
|
1100
|
+
this.messaging.callbackWrapperJunkyard.push(this);
|
|
1101
|
+
}
|
|
1102
|
+
},
|
|
1103
|
+
|
|
1104
|
+
callbackWrapperJunkyard: [],
|
|
1105
|
+
|
|
1106
|
+
callbackWrapperFactory: function(port, msgId) {
|
|
1107
|
+
return this.callbackWrapperJunkyard.length !== 0
|
|
1108
|
+
? this.callbackWrapperJunkyard.pop().init(port, msgId)
|
|
1109
|
+
: new this.CallbackWrapper(this, port, msgId);
|
|
1110
|
+
},
|
|
1111
|
+
|
|
1112
|
+
onPortMessage: function(request, port) {
|
|
1113
|
+
// prepare response
|
|
1114
|
+
let callback = this.NOOPFUNC;
|
|
1115
|
+
if ( request.msgId !== undefined ) {
|
|
1116
|
+
callback = this.callbackWrapperFactory(port, request.msgId).callback;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
// Content process to main process: framework handler.
|
|
1120
|
+
if ( request.channel === 'vapi' ) {
|
|
1121
|
+
this.onFrameworkMessage(request, port, callback);
|
|
1122
|
+
return;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
// Auxiliary process to main process: specific handler
|
|
1126
|
+
const portDetails = this.ports.get(port.name);
|
|
1127
|
+
if ( portDetails === undefined ) { return; }
|
|
1128
|
+
|
|
1129
|
+
const listenerDetails = this.listeners.get(request.channel);
|
|
1130
|
+
let r = this.UNHANDLED;
|
|
1131
|
+
if (
|
|
1132
|
+
(listenerDetails !== undefined) &&
|
|
1133
|
+
(listenerDetails.privileged === false || portDetails.privileged)
|
|
1134
|
+
|
|
1135
|
+
) {
|
|
1136
|
+
r = listenerDetails.fn(request.msg, portDetails, callback);
|
|
1137
|
+
}
|
|
1138
|
+
if ( r !== this.UNHANDLED ) { return; }
|
|
1139
|
+
|
|
1140
|
+
// Auxiliary process to main process: default handler
|
|
1141
|
+
if ( portDetails.privileged ) {
|
|
1142
|
+
r = this.defaultHandler(request.msg, portDetails, callback);
|
|
1143
|
+
if ( r !== this.UNHANDLED ) { return; }
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
// Auxiliary process to main process: no handler
|
|
1147
|
+
ubolog(
|
|
1148
|
+
`vAPI.messaging.onPortMessage > unhandled request: ${JSON.stringify(request.msg)}`,
|
|
1149
|
+
request
|
|
1150
|
+
);
|
|
1151
|
+
|
|
1152
|
+
// Need to callback anyways in case caller expected an answer, or
|
|
1153
|
+
// else there is a memory leak on caller's side
|
|
1154
|
+
callback();
|
|
1155
|
+
},
|
|
1156
|
+
};
|
|
1157
|
+
|
|
1158
|
+
/******************************************************************************/
|
|
1159
|
+
/******************************************************************************/
|
|
1160
|
+
|
|
1161
|
+
// https://github.com/gorhill/uBlock/issues/3474
|
|
1162
|
+
// https://github.com/gorhill/uBlock/issues/2823
|
|
1163
|
+
// Foil ability of web pages to identify uBO through
|
|
1164
|
+
// its web accessible resources.
|
|
1165
|
+
// https://github.com/gorhill/uBlock/issues/3497
|
|
1166
|
+
// Prevent web pages from interfering with uBO's element picker
|
|
1167
|
+
// https://github.com/uBlockOrigin/uBlock-issues/issues/550
|
|
1168
|
+
// Support using a new secret for every network request.
|
|
1169
|
+
|
|
1170
|
+
{
|
|
1171
|
+
// Generate a 6-character alphanumeric string, thus one random value out
|
|
1172
|
+
// of 36^6 = over 2x10^9 values.
|
|
1173
|
+
const generateSecret = ( ) =>
|
|
1174
|
+
(Math.floor(Math.random() * 2176782336) + 2176782336).toString(36).slice(1);
|
|
1175
|
+
|
|
1176
|
+
const root = vAPI.getURL('/');
|
|
1177
|
+
const reSecret = /\?secret=(\w+)/;
|
|
1178
|
+
const shortSecrets = [];
|
|
1179
|
+
let lastShortSecretTime = 0;
|
|
1180
|
+
|
|
1181
|
+
// Long secrets are meant to be used multiple times, but for at most a few
|
|
1182
|
+
// minutes. The realm is one value out of 36^18 = over 10^28 values.
|
|
1183
|
+
const longSecrets = [ '', '' ];
|
|
1184
|
+
let lastLongSecretTimeSlice = 0;
|
|
1185
|
+
|
|
1186
|
+
const guard = details => {
|
|
1187
|
+
const match = reSecret.exec(details.url);
|
|
1188
|
+
if ( match === null ) { return { cancel: true }; }
|
|
1189
|
+
const secret = match[1];
|
|
1190
|
+
if ( longSecrets.includes(secret) ) { return; }
|
|
1191
|
+
const pos = shortSecrets.indexOf(secret);
|
|
1192
|
+
if ( pos === -1 ) { return { cancel: true }; }
|
|
1193
|
+
shortSecrets.splice(pos, 1);
|
|
1194
|
+
};
|
|
1195
|
+
|
|
1196
|
+
browser.webRequest.onBeforeRequest.addListener(
|
|
1197
|
+
guard,
|
|
1198
|
+
{
|
|
1199
|
+
urls: [ root + 'web_accessible_resources/*' ]
|
|
1200
|
+
},
|
|
1201
|
+
[ 'blocking' ]
|
|
1202
|
+
);
|
|
1203
|
+
|
|
1204
|
+
vAPI.warSecret = {
|
|
1205
|
+
short: ( ) => {
|
|
1206
|
+
if ( shortSecrets.length !== 0 ) {
|
|
1207
|
+
if ( (Date.now() - lastShortSecretTime) > 5000 ) {
|
|
1208
|
+
shortSecrets.splice(0);
|
|
1209
|
+
} else if ( shortSecrets.length > 256 ) {
|
|
1210
|
+
shortSecrets.splice(0, shortSecrets.length - 192);
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
lastShortSecretTime = Date.now();
|
|
1214
|
+
const secret = generateSecret();
|
|
1215
|
+
shortSecrets.push(secret);
|
|
1216
|
+
return secret;
|
|
1217
|
+
},
|
|
1218
|
+
long: ( ) => {
|
|
1219
|
+
const timeSlice = Date.now() >>> 19; // Changes every ~9 minutes
|
|
1220
|
+
if ( timeSlice !== lastLongSecretTimeSlice ) {
|
|
1221
|
+
longSecrets[1] = longSecrets[0];
|
|
1222
|
+
longSecrets[0] = `${generateSecret()}${generateSecret()}${generateSecret()}`;
|
|
1223
|
+
lastLongSecretTimeSlice = timeSlice;
|
|
1224
|
+
}
|
|
1225
|
+
return longSecrets[0];
|
|
1226
|
+
},
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
/******************************************************************************/
|
|
1231
|
+
|
|
1232
|
+
vAPI.Net = class {
|
|
1233
|
+
constructor() {
|
|
1234
|
+
this.validTypes = new Set();
|
|
1235
|
+
{
|
|
1236
|
+
const wrrt = browser.webRequest.ResourceType;
|
|
1237
|
+
for ( const typeKey in wrrt ) {
|
|
1238
|
+
if ( wrrt.hasOwnProperty(typeKey) ) {
|
|
1239
|
+
this.validTypes.add(wrrt[typeKey]);
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
}
|
|
1243
|
+
this.suspendableListener = undefined;
|
|
1244
|
+
this.deferredSuspendableListener = undefined;
|
|
1245
|
+
this.listenerMap = new WeakMap();
|
|
1246
|
+
this.suspendDepth = 0;
|
|
1247
|
+
this.unprocessedTabs = new Map();
|
|
1248
|
+
|
|
1249
|
+
browser.webRequest.onBeforeRequest.addListener(
|
|
1250
|
+
details => {
|
|
1251
|
+
this.normalizeDetails(details);
|
|
1252
|
+
if ( this.suspendDepth !== 0 && details.tabId >= 0 ) {
|
|
1253
|
+
return this.suspendOneRequest(details);
|
|
1254
|
+
}
|
|
1255
|
+
return this.onBeforeSuspendableRequest(details);
|
|
1256
|
+
},
|
|
1257
|
+
this.denormalizeFilters({ urls: [ 'http://*/*', 'https://*/*' ] }),
|
|
1258
|
+
[ 'blocking' ]
|
|
1259
|
+
);
|
|
1260
|
+
|
|
1261
|
+
vAPI.setDefaultIcon('-loading', '');
|
|
1262
|
+
}
|
|
1263
|
+
setOptions(/* options */) {
|
|
1264
|
+
}
|
|
1265
|
+
normalizeDetails(/* details */) {
|
|
1266
|
+
}
|
|
1267
|
+
denormalizeFilters(filters) {
|
|
1268
|
+
const urls = filters.urls || [ '<all_urls>' ];
|
|
1269
|
+
let types = filters.types;
|
|
1270
|
+
if ( Array.isArray(types) ) {
|
|
1271
|
+
types = this.denormalizeTypes(types);
|
|
1272
|
+
}
|
|
1273
|
+
if (
|
|
1274
|
+
(this.validTypes.has('websocket')) &&
|
|
1275
|
+
(types === undefined || types.indexOf('websocket') !== -1) &&
|
|
1276
|
+
(urls.indexOf('<all_urls>') === -1)
|
|
1277
|
+
) {
|
|
1278
|
+
if ( urls.indexOf('ws://*/*') === -1 ) {
|
|
1279
|
+
urls.push('ws://*/*');
|
|
1280
|
+
}
|
|
1281
|
+
if ( urls.indexOf('wss://*/*') === -1 ) {
|
|
1282
|
+
urls.push('wss://*/*');
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
return { types, urls };
|
|
1286
|
+
}
|
|
1287
|
+
denormalizeTypes(types) {
|
|
1288
|
+
return types;
|
|
1289
|
+
}
|
|
1290
|
+
canonicalNameFromHostname(/* hn */) {
|
|
1291
|
+
}
|
|
1292
|
+
addListener(which, clientListener, filters, options) {
|
|
1293
|
+
const actualFilters = this.denormalizeFilters(filters);
|
|
1294
|
+
const actualListener = this.makeNewListenerProxy(clientListener);
|
|
1295
|
+
browser.webRequest[which].addListener(
|
|
1296
|
+
actualListener,
|
|
1297
|
+
actualFilters,
|
|
1298
|
+
options
|
|
1299
|
+
);
|
|
1300
|
+
}
|
|
1301
|
+
onBeforeSuspendableRequest(details) {
|
|
1302
|
+
if ( this.suspendableListener !== undefined ) {
|
|
1303
|
+
return this.suspendableListener(details);
|
|
1304
|
+
}
|
|
1305
|
+
this.onUnprocessedRequest(details);
|
|
1306
|
+
}
|
|
1307
|
+
setSuspendableListener(listener) {
|
|
1308
|
+
for ( const [ tabId, requests ] of this.unprocessedTabs ) {
|
|
1309
|
+
let i = requests.length;
|
|
1310
|
+
while ( i-- ) {
|
|
1311
|
+
const r = listener(requests[i]);
|
|
1312
|
+
if ( r === undefined || r.cancel !== true ) {
|
|
1313
|
+
requests.splice(i, 1);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
if ( requests.length !== 0 ) { continue; }
|
|
1317
|
+
this.unprocessedTabs.delete(tabId);
|
|
1318
|
+
}
|
|
1319
|
+
if ( this.unprocessedTabs.size !== 0 ) {
|
|
1320
|
+
this.deferredSuspendableListener = listener;
|
|
1321
|
+
listener = details => {
|
|
1322
|
+
const { tabId, type } = details;
|
|
1323
|
+
if ( type === 'main_frame' && this.unprocessedTabs.has(tabId) ) {
|
|
1324
|
+
if ( this.removeUnprocessedRequest(tabId) ) {
|
|
1325
|
+
return this.suspendableListener(details);
|
|
1326
|
+
}
|
|
1327
|
+
}
|
|
1328
|
+
return this.deferredSuspendableListener(details);
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
this.suspendableListener = listener;
|
|
1332
|
+
vAPI.setDefaultIcon('', '');
|
|
1333
|
+
}
|
|
1334
|
+
removeListener(which, clientListener) {
|
|
1335
|
+
const actualListener = this.listenerMap.get(clientListener);
|
|
1336
|
+
if ( actualListener === undefined ) { return; }
|
|
1337
|
+
this.listenerMap.delete(clientListener);
|
|
1338
|
+
browser.webRequest[which].removeListener(actualListener);
|
|
1339
|
+
}
|
|
1340
|
+
makeNewListenerProxy(clientListener) {
|
|
1341
|
+
const actualListener = details => {
|
|
1342
|
+
this.normalizeDetails(details);
|
|
1343
|
+
return clientListener(details);
|
|
1344
|
+
};
|
|
1345
|
+
this.listenerMap.set(clientListener, actualListener);
|
|
1346
|
+
return actualListener;
|
|
1347
|
+
}
|
|
1348
|
+
handlerBehaviorChanged() {
|
|
1349
|
+
browser.webRequest.handlerBehaviorChanged();
|
|
1350
|
+
}
|
|
1351
|
+
onUnprocessedRequest(details) {
|
|
1352
|
+
const { tabId } = details;
|
|
1353
|
+
if ( tabId === -1 ) { return; }
|
|
1354
|
+
if ( this.unprocessedTabs.size === 0 ) {
|
|
1355
|
+
vAPI.setDefaultIcon('-loading', '!');
|
|
1356
|
+
}
|
|
1357
|
+
let requests = this.unprocessedTabs.get(tabId);
|
|
1358
|
+
if ( requests === undefined ) {
|
|
1359
|
+
this.unprocessedTabs.set(tabId, (requests = []));
|
|
1360
|
+
}
|
|
1361
|
+
requests.push(Object.assign({}, details));
|
|
1362
|
+
}
|
|
1363
|
+
hasUnprocessedRequest(tabId) {
|
|
1364
|
+
if ( this.unprocessedTabs.size === 0 ) { return false; }
|
|
1365
|
+
if ( tabId === undefined ) { return true; }
|
|
1366
|
+
return this.unprocessedTabs.has(tabId);
|
|
1367
|
+
}
|
|
1368
|
+
removeUnprocessedRequest(tabId) {
|
|
1369
|
+
if ( this.deferredSuspendableListener === undefined ) {
|
|
1370
|
+
this.unprocessedTabs.clear();
|
|
1371
|
+
return true;
|
|
1372
|
+
}
|
|
1373
|
+
if ( tabId !== undefined ) {
|
|
1374
|
+
this.unprocessedTabs.delete(tabId);
|
|
1375
|
+
} else {
|
|
1376
|
+
this.unprocessedTabs.clear();
|
|
1377
|
+
}
|
|
1378
|
+
if ( this.unprocessedTabs.size !== 0 ) { return false; }
|
|
1379
|
+
this.suspendableListener = this.deferredSuspendableListener;
|
|
1380
|
+
this.deferredSuspendableListener = undefined;
|
|
1381
|
+
return true;
|
|
1382
|
+
}
|
|
1383
|
+
suspendOneRequest() {
|
|
1384
|
+
}
|
|
1385
|
+
unsuspendAllRequests() {
|
|
1386
|
+
}
|
|
1387
|
+
suspend() {
|
|
1388
|
+
this.suspendDepth += 1;
|
|
1389
|
+
}
|
|
1390
|
+
unsuspend({ all = false, discard = false } = {}) {
|
|
1391
|
+
if ( this.suspendDepth === 0 ) { return; }
|
|
1392
|
+
if ( all ) {
|
|
1393
|
+
this.suspendDepth = 0;
|
|
1394
|
+
} else {
|
|
1395
|
+
this.suspendDepth -= 1;
|
|
1396
|
+
}
|
|
1397
|
+
if ( this.suspendDepth !== 0 ) { return; }
|
|
1398
|
+
this.unsuspendAllRequests(discard);
|
|
1399
|
+
}
|
|
1400
|
+
static canSuspend() {
|
|
1401
|
+
return false;
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
|
|
1405
|
+
/******************************************************************************/
|
|
1406
|
+
/******************************************************************************/
|
|
1407
|
+
|
|
1408
|
+
// To be defined by platform-specific code.
|
|
1409
|
+
|
|
1410
|
+
vAPI.scriptletsInjector = (( ) => {
|
|
1411
|
+
self.uBO_scriptletsInjected = '';
|
|
1412
|
+
}).toString();
|
|
1413
|
+
|
|
1414
|
+
/******************************************************************************/
|
|
1415
|
+
/******************************************************************************/
|
|
1416
|
+
|
|
1417
|
+
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus#Browser_compatibility
|
|
1418
|
+
// Firefox for Android does no support browser.contextMenus.
|
|
1419
|
+
|
|
1420
|
+
vAPI.contextMenu = webext.menus && {
|
|
1421
|
+
_callback: null,
|
|
1422
|
+
_hash: '',
|
|
1423
|
+
onMustUpdate: function() {},
|
|
1424
|
+
setEntries: function(entries, callback) {
|
|
1425
|
+
entries = entries || [];
|
|
1426
|
+
const hash = entries.map(v => v.id).join();
|
|
1427
|
+
if ( hash === this._hash ) { return; }
|
|
1428
|
+
this._hash = hash;
|
|
1429
|
+
webext.menus.removeAll();
|
|
1430
|
+
for ( const entry of entries ) {
|
|
1431
|
+
webext.menus.create(JSON.parse(JSON.stringify(entry)));
|
|
1432
|
+
}
|
|
1433
|
+
const n = entries.length;
|
|
1434
|
+
callback = callback || null;
|
|
1435
|
+
if ( callback === this._callback ) { return; }
|
|
1436
|
+
if ( n !== 0 && callback !== null ) {
|
|
1437
|
+
webext.menus.onClicked.addListener(callback);
|
|
1438
|
+
this._callback = callback;
|
|
1439
|
+
} else if ( n === 0 && this._callback !== null ) {
|
|
1440
|
+
webext.menus.onClicked.removeListener(this._callback);
|
|
1441
|
+
this._callback = null;
|
|
1442
|
+
}
|
|
1443
|
+
}
|
|
1444
|
+
};
|
|
1445
|
+
|
|
1446
|
+
/******************************************************************************/
|
|
1447
|
+
/******************************************************************************/
|
|
1448
|
+
|
|
1449
|
+
vAPI.commands = browser.commands;
|
|
1450
|
+
|
|
1451
|
+
/******************************************************************************/
|
|
1452
|
+
/******************************************************************************/
|
|
1453
|
+
|
|
1454
|
+
// https://github.com/gorhill/uBlock/issues/531
|
|
1455
|
+
// Storage area dedicated to admin settings. Read-only.
|
|
1456
|
+
|
|
1457
|
+
// https://github.com/gorhill/uBlock/commit/43a5ed735b95a575a9339b6e71a1fcb27a99663b#commitcomment-13965030
|
|
1458
|
+
// Not all Chromium-based browsers support managed storage. Merely testing or
|
|
1459
|
+
// exception handling in this case does NOT work: I don't know why. The
|
|
1460
|
+
// extension on Opera ends up in a non-sensical state, whereas vAPI become
|
|
1461
|
+
// undefined out of nowhere. So only solution left is to test explicitly for
|
|
1462
|
+
// Opera.
|
|
1463
|
+
// https://github.com/gorhill/uBlock/issues/900
|
|
1464
|
+
// Also, UC Browser: http://www.upsieutoc.com/image/WXuH
|
|
1465
|
+
|
|
1466
|
+
// https://github.com/uBlockOrigin/uAssets/discussions/16939
|
|
1467
|
+
// Use a cached version of admin settings, such that there is no blocking
|
|
1468
|
+
// call on `storage.managed`. The side effect is that any changes to admin
|
|
1469
|
+
// settings will require an extra extension restart to take effect.
|
|
1470
|
+
|
|
1471
|
+
vAPI.adminStorage = (( ) => {
|
|
1472
|
+
if ( webext.storage.managed instanceof Object === false ) {
|
|
1473
|
+
return {
|
|
1474
|
+
get: function() {
|
|
1475
|
+
return Promise.resolve();
|
|
1476
|
+
},
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
const cacheManagedStorage = async ( ) => {
|
|
1480
|
+
let store;
|
|
1481
|
+
try {
|
|
1482
|
+
store = await webext.storage.managed.get();
|
|
1483
|
+
} catch(ex) {
|
|
1484
|
+
}
|
|
1485
|
+
webext.storage.local.set({ cachedManagedStorage: store || {} });
|
|
1486
|
+
};
|
|
1487
|
+
|
|
1488
|
+
return {
|
|
1489
|
+
get: async function(key) {
|
|
1490
|
+
let bin;
|
|
1491
|
+
try {
|
|
1492
|
+
bin = await webext.storage.local.get('cachedManagedStorage') || {};
|
|
1493
|
+
if ( Object.keys(bin).length === 0 ) {
|
|
1494
|
+
bin = await webext.storage.managed.get() || {};
|
|
1495
|
+
} else {
|
|
1496
|
+
bin = bin.cachedManagedStorage;
|
|
1497
|
+
}
|
|
1498
|
+
} catch(ex) {
|
|
1499
|
+
bin = {};
|
|
1500
|
+
}
|
|
1501
|
+
cacheManagedStorage();
|
|
1502
|
+
if ( key === undefined || key === null ) {
|
|
1503
|
+
return bin;
|
|
1504
|
+
}
|
|
1505
|
+
if ( typeof key === 'string' && bin instanceof Object ) {
|
|
1506
|
+
return bin[key];
|
|
1507
|
+
}
|
|
1508
|
+
const out = {};
|
|
1509
|
+
if ( Array.isArray(key) ) {
|
|
1510
|
+
for ( const k of key ) {
|
|
1511
|
+
if ( bin[k] === undefined ) { continue; }
|
|
1512
|
+
out[k] = bin[k];
|
|
1513
|
+
}
|
|
1514
|
+
return out;
|
|
1515
|
+
}
|
|
1516
|
+
for ( const [ k, v ] of Object.entries(key) ) {
|
|
1517
|
+
out[k] = bin[k] !== undefined ? bin[k] : v;
|
|
1518
|
+
}
|
|
1519
|
+
return out;
|
|
1520
|
+
}
|
|
1521
|
+
};
|
|
1522
|
+
})();
|
|
1523
|
+
|
|
1524
|
+
/******************************************************************************/
|
|
1525
|
+
/******************************************************************************/
|
|
1526
|
+
|
|
1527
|
+
// A localStorage-like object which should be accessible from the
|
|
1528
|
+
// background page or auxiliary pages.
|
|
1529
|
+
//
|
|
1530
|
+
// https://github.com/uBlockOrigin/uBlock-issues/issues/899
|
|
1531
|
+
// Convert into asynchronous access API.
|
|
1532
|
+
//
|
|
1533
|
+
// Note: vAPI.localStorage should already be defined with the client-side
|
|
1534
|
+
// implementation at this point, but we override with the
|
|
1535
|
+
// background-side implementation.
|
|
1536
|
+
vAPI.localStorage = {
|
|
1537
|
+
start: async function() {
|
|
1538
|
+
if ( this.cache instanceof Promise ) { return this.cache; }
|
|
1539
|
+
if ( this.cache instanceof Object ) { return this.cache; }
|
|
1540
|
+
this.cache = webext.storage.local.get('localStorage').then(bin => {
|
|
1541
|
+
this.cache = bin instanceof Object &&
|
|
1542
|
+
bin.localStorage instanceof Object
|
|
1543
|
+
? bin.localStorage
|
|
1544
|
+
: {};
|
|
1545
|
+
});
|
|
1546
|
+
return this.cache;
|
|
1547
|
+
},
|
|
1548
|
+
clear: function() {
|
|
1549
|
+
this.cache = {};
|
|
1550
|
+
return webext.storage.local.set({ localStorage: this.cache });
|
|
1551
|
+
},
|
|
1552
|
+
getItem: function(key) {
|
|
1553
|
+
if ( this.cache instanceof Object === false ) {
|
|
1554
|
+
console.info(`localStorage.getItem('${key}') not ready`);
|
|
1555
|
+
return null;
|
|
1556
|
+
}
|
|
1557
|
+
const value = this.cache[key];
|
|
1558
|
+
return value !== undefined ? value : null;
|
|
1559
|
+
},
|
|
1560
|
+
getItemAsync: async function(key) {
|
|
1561
|
+
await this.start();
|
|
1562
|
+
const value = this.cache[key];
|
|
1563
|
+
return value !== undefined ? value : null;
|
|
1564
|
+
},
|
|
1565
|
+
removeItem: async function(key) {
|
|
1566
|
+
this.setItem(key);
|
|
1567
|
+
},
|
|
1568
|
+
setItem: async function(key, value = undefined) {
|
|
1569
|
+
await this.start();
|
|
1570
|
+
if ( value === this.cache[key] ) { return; }
|
|
1571
|
+
this.cache[key] = value;
|
|
1572
|
+
return webext.storage.local.set({ localStorage: this.cache });
|
|
1573
|
+
},
|
|
1574
|
+
cache: undefined,
|
|
1575
|
+
};
|
|
1576
|
+
|
|
1577
|
+
vAPI.localStorage.start();
|
|
1578
|
+
|
|
1579
|
+
/******************************************************************************/
|
|
1580
|
+
/******************************************************************************/
|
|
1581
|
+
|
|
1582
|
+
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/sync
|
|
1583
|
+
|
|
1584
|
+
vAPI.cloud = (( ) => {
|
|
1585
|
+
// Not all platforms support `webext.storage.sync`.
|
|
1586
|
+
if ( webext.storage.sync instanceof Object === false ) { return; }
|
|
1587
|
+
|
|
1588
|
+
// Currently, only Chromium supports the following constants -- these
|
|
1589
|
+
// values will be assumed for platforms which do not define them.
|
|
1590
|
+
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage/sync
|
|
1591
|
+
// > You can store up to 100KB of data using this API
|
|
1592
|
+
const MAX_ITEMS =
|
|
1593
|
+
webext.storage.sync.MAX_ITEMS || 512;
|
|
1594
|
+
const QUOTA_BYTES =
|
|
1595
|
+
webext.storage.sync.QUOTA_BYTES || 102400;
|
|
1596
|
+
const QUOTA_BYTES_PER_ITEM =
|
|
1597
|
+
webext.storage.sync.QUOTA_BYTES_PER_ITEM || 8192;
|
|
1598
|
+
|
|
1599
|
+
const chunkCountPerFetch = 16; // Must be a power of 2
|
|
1600
|
+
const maxChunkCountPerItem = Math.floor(MAX_ITEMS * 0.75) & ~(chunkCountPerFetch - 1);
|
|
1601
|
+
|
|
1602
|
+
// https://github.com/gorhill/uBlock/issues/3006
|
|
1603
|
+
// For Firefox, we will use a lower ratio to allow for more overhead for
|
|
1604
|
+
// the infrastructure. Unfortunately this leads to less usable space for
|
|
1605
|
+
// actual data, but all of this is provided for free by browser vendors,
|
|
1606
|
+
// so we need to accept and deal with these limitations.
|
|
1607
|
+
const evalMaxChunkSize = function() {
|
|
1608
|
+
return Math.floor(
|
|
1609
|
+
QUOTA_BYTES_PER_ITEM *
|
|
1610
|
+
(vAPI.webextFlavor.soup.has('firefox') ? 0.6 : 0.75)
|
|
1611
|
+
);
|
|
1612
|
+
};
|
|
1613
|
+
|
|
1614
|
+
let maxChunkSize = evalMaxChunkSize();
|
|
1615
|
+
|
|
1616
|
+
// The real actual webextFlavor value may not be set in stone, so listen
|
|
1617
|
+
// for possible future changes.
|
|
1618
|
+
window.addEventListener('webextFlavor', function() {
|
|
1619
|
+
maxChunkSize = evalMaxChunkSize();
|
|
1620
|
+
}, { once: true });
|
|
1621
|
+
|
|
1622
|
+
const options = {
|
|
1623
|
+
defaultDeviceName: window.navigator.platform,
|
|
1624
|
+
deviceName: undefined,
|
|
1625
|
+
};
|
|
1626
|
+
|
|
1627
|
+
vAPI.localStorage.getItemAsync('deviceName').then(value => {
|
|
1628
|
+
options.deviceName = value;
|
|
1629
|
+
});
|
|
1630
|
+
|
|
1631
|
+
// This is used to find out a rough count of how many chunks exists:
|
|
1632
|
+
// We "poll" at specific index in order to get a rough idea of how
|
|
1633
|
+
// large is the stored string.
|
|
1634
|
+
// This allows reading a single item with only 2 sync operations -- a
|
|
1635
|
+
// good thing given chrome.storage.sync.MAX_WRITE_OPERATIONS_PER_MINUTE
|
|
1636
|
+
// and chrome.storage.sync.MAX_WRITE_OPERATIONS_PER_HOUR.
|
|
1637
|
+
|
|
1638
|
+
const getCoarseChunkCount = async function(datakey) {
|
|
1639
|
+
const keys = {};
|
|
1640
|
+
for ( let i = 0; i < maxChunkCountPerItem; i += 16 ) {
|
|
1641
|
+
keys[datakey + i.toString()] = '';
|
|
1642
|
+
}
|
|
1643
|
+
let bin;
|
|
1644
|
+
try {
|
|
1645
|
+
bin = await webext.storage.sync.get(keys);
|
|
1646
|
+
} catch (reason) {
|
|
1647
|
+
return String(reason);
|
|
1648
|
+
}
|
|
1649
|
+
let chunkCount = 0;
|
|
1650
|
+
for ( let i = 0; i < maxChunkCountPerItem; i += 16 ) {
|
|
1651
|
+
if ( bin[datakey + i.toString()] === '' ) { break; }
|
|
1652
|
+
chunkCount = i + 16;
|
|
1653
|
+
}
|
|
1654
|
+
return chunkCount;
|
|
1655
|
+
};
|
|
1656
|
+
|
|
1657
|
+
const deleteChunks = async function(datakey, start) {
|
|
1658
|
+
const keys = [];
|
|
1659
|
+
|
|
1660
|
+
const n = await getCoarseChunkCount(datakey);
|
|
1661
|
+
for ( let i = start; i < n; i++ ) {
|
|
1662
|
+
keys.push(datakey + i.toString());
|
|
1663
|
+
}
|
|
1664
|
+
if ( keys.length !== 0 ) {
|
|
1665
|
+
webext.storage.sync.remove(keys);
|
|
1666
|
+
}
|
|
1667
|
+
};
|
|
1668
|
+
|
|
1669
|
+
const push = async function(details) {
|
|
1670
|
+
const { datakey, data, encode } = details;
|
|
1671
|
+
if (
|
|
1672
|
+
data === undefined ||
|
|
1673
|
+
typeof data === 'string' && data === ''
|
|
1674
|
+
) {
|
|
1675
|
+
return deleteChunks(datakey, 0);
|
|
1676
|
+
}
|
|
1677
|
+
const item = {
|
|
1678
|
+
source: options.deviceName || options.defaultDeviceName,
|
|
1679
|
+
tstamp: Date.now(),
|
|
1680
|
+
data,
|
|
1681
|
+
};
|
|
1682
|
+
const json = JSON.stringify(item);
|
|
1683
|
+
const encoded = encode instanceof Function
|
|
1684
|
+
? await encode(json)
|
|
1685
|
+
: json;
|
|
1686
|
+
|
|
1687
|
+
// Chunkify taking into account QUOTA_BYTES_PER_ITEM:
|
|
1688
|
+
// https://developer.chrome.com/extensions/storage#property-sync
|
|
1689
|
+
// "The maximum size (in bytes) of each individual item in sync
|
|
1690
|
+
// "storage, as measured by the JSON stringification of its value
|
|
1691
|
+
// "plus its key length."
|
|
1692
|
+
const bin = {};
|
|
1693
|
+
const chunkCount = Math.ceil(encoded.length / maxChunkSize);
|
|
1694
|
+
for ( let i = 0; i < chunkCount; i++ ) {
|
|
1695
|
+
bin[datakey + i.toString()]
|
|
1696
|
+
= encoded.substr(i * maxChunkSize, maxChunkSize);
|
|
1697
|
+
}
|
|
1698
|
+
bin[datakey + chunkCount.toString()] = ''; // Sentinel
|
|
1699
|
+
|
|
1700
|
+
// Remove potentially unused trailing chunks before storing the data,
|
|
1701
|
+
// this will free storage space which could otherwise cause the push
|
|
1702
|
+
// operation to fail.
|
|
1703
|
+
try {
|
|
1704
|
+
await deleteChunks(datakey, chunkCount + 1);
|
|
1705
|
+
} catch (reason) {
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
// Push the data to browser-provided cloud storage.
|
|
1709
|
+
try {
|
|
1710
|
+
await webext.storage.sync.set(bin);
|
|
1711
|
+
} catch (reason) {
|
|
1712
|
+
return String(reason);
|
|
1713
|
+
}
|
|
1714
|
+
};
|
|
1715
|
+
|
|
1716
|
+
const pull = async function(details) {
|
|
1717
|
+
const { datakey, decode } = details;
|
|
1718
|
+
|
|
1719
|
+
const result = await getCoarseChunkCount(datakey);
|
|
1720
|
+
if ( typeof result !== 'number' ) {
|
|
1721
|
+
return result;
|
|
1722
|
+
}
|
|
1723
|
+
const chunkKeys = {};
|
|
1724
|
+
for ( let i = 0; i < result; i++ ) {
|
|
1725
|
+
chunkKeys[datakey + i.toString()] = '';
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
let bin;
|
|
1729
|
+
try {
|
|
1730
|
+
bin = await webext.storage.sync.get(chunkKeys);
|
|
1731
|
+
} catch (reason) {
|
|
1732
|
+
return String(reason);
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
// Assemble chunks into a single string.
|
|
1736
|
+
// https://www.reddit.com/r/uMatrix/comments/8lc9ia/my_rules_tab_hangs_with_cloud_storage_support/
|
|
1737
|
+
// Explicit sentinel is not necessarily present: this can
|
|
1738
|
+
// happen when the number of chunks is a multiple of
|
|
1739
|
+
// chunkCountPerFetch. Hence why we must also test against
|
|
1740
|
+
// undefined.
|
|
1741
|
+
let encoded = [];
|
|
1742
|
+
let i = 0;
|
|
1743
|
+
for (;;) {
|
|
1744
|
+
const slice = bin[datakey + i.toString()];
|
|
1745
|
+
if ( slice === '' || slice === undefined ) { break; }
|
|
1746
|
+
encoded.push(slice);
|
|
1747
|
+
i += 1;
|
|
1748
|
+
}
|
|
1749
|
+
encoded = encoded.join('');
|
|
1750
|
+
const json = decode instanceof Function
|
|
1751
|
+
? await decode(encoded)
|
|
1752
|
+
: encoded;
|
|
1753
|
+
let entry = null;
|
|
1754
|
+
try {
|
|
1755
|
+
entry = JSON.parse(json);
|
|
1756
|
+
} catch(ex) {
|
|
1757
|
+
}
|
|
1758
|
+
return entry;
|
|
1759
|
+
};
|
|
1760
|
+
|
|
1761
|
+
const used = async function(datakey) {
|
|
1762
|
+
if ( webext.storage.sync.getBytesInUse instanceof Function === false ) {
|
|
1763
|
+
return;
|
|
1764
|
+
}
|
|
1765
|
+
const coarseCount = await getCoarseChunkCount(datakey);
|
|
1766
|
+
if ( typeof coarseCount !== 'number' ) { return; }
|
|
1767
|
+
const keys = [];
|
|
1768
|
+
for ( let i = 0; i < coarseCount; i++ ) {
|
|
1769
|
+
keys.push(`${datakey}${i}`);
|
|
1770
|
+
}
|
|
1771
|
+
let results;
|
|
1772
|
+
try {
|
|
1773
|
+
results = await Promise.all([
|
|
1774
|
+
webext.storage.sync.getBytesInUse(keys),
|
|
1775
|
+
webext.storage.sync.getBytesInUse(null),
|
|
1776
|
+
]);
|
|
1777
|
+
} catch(ex) {
|
|
1778
|
+
}
|
|
1779
|
+
if ( Array.isArray(results) === false ) { return; }
|
|
1780
|
+
return { used: results[0], total: results[1], max: QUOTA_BYTES };
|
|
1781
|
+
};
|
|
1782
|
+
|
|
1783
|
+
const getOptions = function(callback) {
|
|
1784
|
+
if ( typeof callback !== 'function' ) { return; }
|
|
1785
|
+
callback(options);
|
|
1786
|
+
};
|
|
1787
|
+
|
|
1788
|
+
const setOptions = function(details, callback) {
|
|
1789
|
+
if ( typeof details !== 'object' || details === null ) { return; }
|
|
1790
|
+
|
|
1791
|
+
if ( typeof details.deviceName === 'string' ) {
|
|
1792
|
+
vAPI.localStorage.setItem('deviceName', details.deviceName);
|
|
1793
|
+
options.deviceName = details.deviceName;
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
getOptions(callback);
|
|
1797
|
+
};
|
|
1798
|
+
|
|
1799
|
+
return { push, pull, used, getOptions, setOptions };
|
|
1800
|
+
})();
|
|
1801
|
+
|
|
1802
|
+
/******************************************************************************/
|