2014-06-24 00:42:43 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2016-06-29 04:01:15 +02:00
|
|
|
uBlock Origin - a browser extension to block requests.
|
2018-08-06 18:34:41 +02:00
|
|
|
Copyright (C) 2014-present Raymond Hill
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see {http://www.gnu.org/licenses/}.
|
|
|
|
|
|
|
|
Home: https://github.com/gorhill/uBlock
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2017-03-05 14:25:55 +01:00
|
|
|
'use strict';
|
2014-08-21 05:19:27 +02:00
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
2018-04-05 13:29:15 +02:00
|
|
|
// Not all platforms may have properly declared vAPI.webextFlavor.
|
|
|
|
|
|
|
|
if ( vAPI.webextFlavor === undefined ) {
|
2018-04-18 13:11:13 +02:00
|
|
|
vAPI.webextFlavor = { major: 0, soup: new Set([ 'ublock' ]) };
|
2018-04-05 13:29:15 +02:00
|
|
|
}
|
|
|
|
|
2018-04-18 13:11:13 +02:00
|
|
|
|
2018-04-05 13:29:15 +02:00
|
|
|
/******************************************************************************/
|
|
|
|
|
2019-09-21 17:30:38 +02:00
|
|
|
const µBlock = (( ) => { // jshint ignore:line
|
2014-09-26 03:21:55 +02:00
|
|
|
|
2018-11-03 12:58:46 +01:00
|
|
|
const hiddenSettingsDefault = {
|
2019-05-19 00:57:32 +02:00
|
|
|
allowGenericProceduralFilters: false,
|
2017-01-18 19:17:47 +01:00
|
|
|
assetFetchTimeout: 30,
|
2019-01-08 13:37:50 +01:00
|
|
|
autoCommentFilterTemplate: '{{date}} {{origin}}',
|
2017-01-18 19:17:47 +01:00
|
|
|
autoUpdateAssetFetchPeriod: 120,
|
2019-05-20 00:31:12 +02:00
|
|
|
autoUpdateDelayAfterLaunch: 180,
|
2021-01-21 14:40:10 +01:00
|
|
|
autoUpdatePeriod: 4,
|
2020-02-21 14:06:52 +01:00
|
|
|
benchmarkDatasetURL: 'unset',
|
2020-12-12 20:33:49 +01:00
|
|
|
blockingProfiles: '11111/#F00 11010/#C0F 11001/#00F 00001',
|
2019-01-26 00:49:30 +01:00
|
|
|
cacheStorageAPI: 'unset',
|
2018-08-21 18:59:35 +02:00
|
|
|
cacheStorageCompression: true,
|
2018-09-21 15:16:46 +02:00
|
|
|
cacheControlForFirefox1376932: 'no-cache, no-store, must-revalidate',
|
2020-11-13 18:14:06 +01:00
|
|
|
cloudStorageCompression: true,
|
2019-11-19 18:05:33 +01:00
|
|
|
cnameIgnoreList: 'unset',
|
|
|
|
cnameIgnore1stParty: true,
|
2019-12-01 18:05:49 +01:00
|
|
|
cnameIgnoreExceptions: true,
|
2019-11-23 18:46:52 +01:00
|
|
|
cnameIgnoreRootDocument: true,
|
2019-12-31 22:36:51 +01:00
|
|
|
cnameMaxTTL: 120,
|
2019-11-23 18:46:52 +01:00
|
|
|
cnameReplayFullURL: false,
|
2019-12-01 18:05:49 +01:00
|
|
|
cnameUncloak: true,
|
2020-03-22 19:52:58 +01:00
|
|
|
cnameUncloakProxied: false,
|
2019-02-14 19:33:55 +01:00
|
|
|
consoleLogLevel: 'unset',
|
2018-11-16 16:19:06 +01:00
|
|
|
debugScriptlets: false,
|
2019-07-03 20:33:06 +02:00
|
|
|
debugScriptletInjector: false,
|
2018-11-16 16:19:06 +01:00
|
|
|
disableWebAssembly: false,
|
2019-09-11 14:00:55 +02:00
|
|
|
extensionUpdateForceReload: false,
|
Add support for `1P`, `3P`, `header=` filter options and other changes
New filter options
==================
Strict partyness: `1P`, `3P`
----------------------------
The current options 1p/3p are meant to "weakly" match partyness, i.e. a
network request is considered 1st-party to its context as long as both the
context and the request share the same base domain.
The new partyness options are meant to check for strict partyness, i.e. a
network request will be considered 1st-party if and only if both the context
and the request share the same hostname.
For examples:
- context: `www.example.org`
- request: `www.example.org`
- `1p`: yes, `1P`: yes
- `3p`: no, `3P`: no
- context: `www.example.org`
- request: `subdomain.example.org`
- `1p`: yes, `1P`: no
- `3p`: no, `3P`: yes
- context: `www.example.org`
- request: `www.example.com`
- `1p`: no, `1P`: no
- `3p`: yes, `3P`: yes
The strict partyness options will be visually emphasized in the editor so as
to prevent mistakenly using `1P` or `3P` where weak partyness is meant to be
used.
Filter on response headers: `header=`
-------------------------------------
Currently experimental and under evaluation. Disabled by default, enable by
toggling `filterOnHeaders` to `true` in advanced settings.
Ability to filter network requests according to whether a specific response
header is present and whether it matches or does not match a specific value.
For example:
*$1p,3P,script,header=via:1\.1\s+google
The above filter is meant to block network requests which fullfill all the
following conditions:
- is weakly 1st-party to the context
- is not strictly 1st-party to the context
- is of type `script`
- has a response HTTP header named `via`, which value matches the regular
expression `1\.1\s+google`.
The matches are always performed in a case-insensitive manner.
The header value is assumed to be a literal regular expression, except for
the following special characters:
- to anchor to start of string, use leading `|`, not `^`
- to anchor to end of string, use trailing `|`, not `$`
- to invert the test, use a leading `!`
To block a network request if it merely contains a specific HTTP header is
just a matter of specifying the header name without a header value:
*$1p,3P,script,header=via
Generic exception filters can be used to disable specific block `header=`
filters, i.e. `@@*$1p,3P,script,header` will override the block `header=`
filters given as example above.
Dynamic filtering's `allow` rules override block `headers=` filters.
Important: It is key that filter authors use as many narrowing filter options
as possible when using the `header=` option, and the `header=` option should
be used ONLY when other filter options are not sufficient.
More documentation justifying the purpose of `header=` option will be
provided eventually if ever it is decided to move it from experimental to
stable status.
To be decided: to restrict usage of this filter option to only uBO's own
filter lists or "My filters".
Changes
=======
Fine tuning `queryprune=`
-------------------------
The following changes have been implemented:
The special value `*` (i.e. `queryprune=*`) means "remove all query
parameters".
If the `queryprune=` value is made only of alphanumeric characters
(including `_`), the value will be internally converted to regex equivalent
`^value=`. This ensures a better future compatibility with AdGuard's
`removeparam=`.
If the `queryprune=` value starts with `!`, the test will be inverted. This
can be used to remove all query parameters EXCEPT those who match the
specified value.
Other
-----
The legacy code to test for spurious CSP reports has been removed. This
is no longer an issue ever since uBO redirects to local resources through
web accessible resources.
Notes
=====
The following new and recently added filter options are not compatible with
Chromium's manifest v3 changes:
- `queryprune=`
- `1P`
- `3P`
- `header=`
2020-11-23 14:22:43 +01:00
|
|
|
filterAuthorMode: false,
|
|
|
|
filterOnHeaders: false,
|
2016-11-03 16:20:47 +01:00
|
|
|
ignoreRedirectFilters: false,
|
|
|
|
ignoreScriptInjectFilters: false,
|
2019-09-06 17:41:07 +02:00
|
|
|
loggerPopupType: 'popup',
|
2018-04-09 14:26:14 +02:00
|
|
|
manualUpdateAssetFetchPeriod: 500,
|
2016-11-06 22:27:21 +01:00
|
|
|
popupFontSize: 'unset',
|
2020-05-02 01:47:01 +02:00
|
|
|
popupPanelDisabledSections: 0,
|
|
|
|
popupPanelLockedSections: 0,
|
2020-05-22 14:47:51 +02:00
|
|
|
popupPanelHeightMode: 0,
|
2018-09-01 00:47:02 +02:00
|
|
|
requestJournalProcessPeriod: 1000,
|
2019-05-18 20:43:44 +02:00
|
|
|
selfieAfter: 3,
|
2018-10-29 13:56:51 +01:00
|
|
|
strictBlockingBypassDuration: 120,
|
2019-02-19 18:30:37 +01:00
|
|
|
suspendTabsUntilReady: 'unset',
|
2020-04-27 16:33:49 +02:00
|
|
|
uiPopupConfig: 'undocumented',
|
2020-01-25 15:24:59 +01:00
|
|
|
uiFlavor: 'unset',
|
2020-05-19 16:33:36 +02:00
|
|
|
uiStyles: 'unset',
|
2020-10-03 13:13:40 +02:00
|
|
|
uiTheme: 'unset',
|
2019-07-26 15:52:11 +02:00
|
|
|
updateAssetBypassBrowserCache: false,
|
2019-05-19 00:57:32 +02:00
|
|
|
userResourcesLocation: 'unset',
|
2017-03-05 14:25:55 +01:00
|
|
|
};
|
|
|
|
|
2021-01-16 16:35:56 +01:00
|
|
|
const userSettingsDefault = {
|
|
|
|
advancedUserEnabled: false,
|
|
|
|
alwaysDetachLogger: true,
|
|
|
|
autoUpdate: true,
|
|
|
|
cloudStorageEnabled: false,
|
2021-03-02 19:00:56 +01:00
|
|
|
cnameUncloakEnabled: true,
|
2021-01-16 16:35:56 +01:00
|
|
|
collapseBlocked: true,
|
|
|
|
colorBlindFriendly: false,
|
|
|
|
contextMenuEnabled: true,
|
|
|
|
dynamicFilteringEnabled: false,
|
2021-01-31 16:30:12 +01:00
|
|
|
externalLists: '',
|
2021-01-16 16:35:56 +01:00
|
|
|
firewallPaneMinimized: true,
|
|
|
|
hyperlinkAuditingDisabled: true,
|
|
|
|
ignoreGenericCosmeticFilters: vAPI.webextFlavor.soup.has('mobile'),
|
2021-01-31 16:30:12 +01:00
|
|
|
importedLists: [],
|
2021-01-16 16:35:56 +01:00
|
|
|
largeMediaSize: 50,
|
|
|
|
parseAllABPHideFilters: true,
|
|
|
|
popupPanelSections: 0b111,
|
|
|
|
prefetchingDisabled: true,
|
|
|
|
requestLogMaxEntries: 1000,
|
|
|
|
showIconBadge: true,
|
|
|
|
tooltipsDisabled: false,
|
|
|
|
webrtcIPAddressHidden: false,
|
|
|
|
};
|
|
|
|
|
2017-03-05 14:25:55 +01:00
|
|
|
return {
|
2021-01-16 16:35:56 +01:00
|
|
|
userSettingsDefault: userSettingsDefault,
|
|
|
|
userSettings: Object.assign({}, userSettingsDefault),
|
2017-03-05 14:25:55 +01:00
|
|
|
|
|
|
|
hiddenSettingsDefault: hiddenSettingsDefault,
|
2021-01-05 18:16:50 +01:00
|
|
|
hiddenSettingsAdmin: {},
|
2020-02-23 18:18:45 +01:00
|
|
|
hiddenSettings: Object.assign({}, hiddenSettingsDefault),
|
2017-03-05 14:25:55 +01:00
|
|
|
|
2021-01-06 17:39:24 +01:00
|
|
|
noDashboard: false,
|
|
|
|
|
2017-03-05 14:25:55 +01:00
|
|
|
// Features detection.
|
|
|
|
privacySettingsSupported: vAPI.browserSettings instanceof Object,
|
|
|
|
cloudStorageSupported: vAPI.cloud instanceof Object,
|
2018-10-28 14:58:25 +01:00
|
|
|
canFilterResponseData: typeof browser.webRequest.filterResponseData === 'function',
|
2018-05-18 16:19:14 +02:00
|
|
|
canInjectScriptletsNow: vAPI.webextFlavor.soup.has('chromium'),
|
2017-03-05 14:25:55 +01:00
|
|
|
|
|
|
|
// https://github.com/chrisaljoudi/uBlock/issues/180
|
|
|
|
// Whitelist directives need to be loaded once the PSL is available
|
2019-06-25 17:57:14 +02:00
|
|
|
netWhitelist: new Map(),
|
2017-03-05 14:25:55 +01:00
|
|
|
netWhitelistModifyTime: 0,
|
2019-05-18 20:20:05 +02:00
|
|
|
netWhitelistDefault: [
|
|
|
|
'about-scheme',
|
|
|
|
'chrome-extension-scheme',
|
|
|
|
'chrome-scheme',
|
2020-02-20 22:43:56 +01:00
|
|
|
'edge-scheme',
|
2019-05-18 20:20:05 +02:00
|
|
|
'moz-extension-scheme',
|
|
|
|
'opera-scheme',
|
|
|
|
'vivaldi-scheme',
|
|
|
|
'wyciwyg-scheme', // Firefox's "What-You-Cache-Is-What-You-Get"
|
|
|
|
],
|
2017-03-05 14:25:55 +01:00
|
|
|
|
|
|
|
localSettings: {
|
|
|
|
blockedRequestCount: 0,
|
2019-09-21 17:30:38 +02:00
|
|
|
allowedRequestCount: 0,
|
2017-03-05 14:25:55 +01:00
|
|
|
},
|
|
|
|
localSettingsLastModified: 0,
|
|
|
|
localSettingsLastSaved: 0,
|
|
|
|
|
2018-05-31 16:41:03 +02:00
|
|
|
// Read-only
|
2017-03-05 14:25:55 +01:00
|
|
|
systemSettings: {
|
2020-11-29 17:02:40 +01:00
|
|
|
compiledMagic: 37, // Increase when compiled format changes
|
|
|
|
selfieMagic: 37, // Increase when selfie format changes
|
2017-03-05 14:25:55 +01:00
|
|
|
},
|
|
|
|
|
2019-10-27 16:49:05 +01:00
|
|
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/759#issuecomment-546654501
|
|
|
|
// The assumption is that cache storage state reflects whether
|
|
|
|
// compiled or selfie assets are available or not. The properties
|
|
|
|
// below is to no longer rely on this assumption -- though it's still
|
|
|
|
// not clear how the assumption could be wrong, and it's still not
|
|
|
|
// clear whether relying on those properties will really solve the
|
|
|
|
// issue. It's just an attempt at hardening.
|
|
|
|
compiledFormatChanged: false,
|
|
|
|
selfieIsInvalid: false,
|
|
|
|
|
2020-12-08 16:00:47 +01:00
|
|
|
compiledNetworkSection: 100,
|
|
|
|
compiledCosmeticSection: 200,
|
|
|
|
compiledScriptletSection: 300,
|
|
|
|
compiledHTMLSection: 400,
|
|
|
|
compiledSentinelSection: 1000,
|
|
|
|
compiledBadSubsection: 1,
|
|
|
|
|
2017-03-05 14:25:55 +01:00
|
|
|
restoreBackupSettings: {
|
|
|
|
lastRestoreFile: '',
|
|
|
|
lastRestoreTime: 0,
|
|
|
|
lastBackupFile: '',
|
2019-09-21 17:30:38 +02:00
|
|
|
lastBackupTime: 0,
|
2017-03-05 14:25:55 +01:00
|
|
|
},
|
|
|
|
|
2018-07-19 00:00:55 +02:00
|
|
|
commandShortcuts: new Map(),
|
|
|
|
|
2017-03-05 14:25:55 +01:00
|
|
|
// Allows to fully customize uBO's assets, typically set through admin
|
|
|
|
// settings. The content of 'assets.json' will also tell which filter
|
|
|
|
// lists to enable by default when uBO is first installed.
|
2019-07-18 16:53:08 +02:00
|
|
|
assetsBootstrapLocation: undefined,
|
2017-03-05 14:25:55 +01:00
|
|
|
|
|
|
|
userFiltersPath: 'user-filters',
|
|
|
|
pslAssetKey: 'public_suffix_list.dat',
|
|
|
|
|
|
|
|
selectedFilterLists: [],
|
|
|
|
availableFilterLists: {},
|
2020-08-22 14:43:16 +02:00
|
|
|
badLists: new Map(),
|
2017-03-05 14:25:55 +01:00
|
|
|
|
2020-04-04 17:34:43 +02:00
|
|
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/974
|
|
|
|
// This can be used to defer filtering decision-making.
|
|
|
|
readyToFilter: false,
|
|
|
|
|
2018-02-26 19:59:16 +01:00
|
|
|
pageStores: new Map(),
|
2017-03-05 14:25:55 +01:00
|
|
|
pageStoresToken: 0,
|
|
|
|
|
|
|
|
storageQuota: vAPI.storage.QUOTA_BYTES,
|
|
|
|
storageUsed: 0,
|
|
|
|
|
|
|
|
noopFunc: function(){},
|
|
|
|
|
|
|
|
apiErrorCount: 0,
|
2017-09-06 01:49:48 +02:00
|
|
|
|
2019-09-18 18:17:45 +02:00
|
|
|
maybeGoodPopup: {
|
|
|
|
tabId: 0,
|
|
|
|
url: '',
|
2017-09-06 01:49:48 +02:00
|
|
|
},
|
|
|
|
|
2019-09-18 18:17:45 +02:00
|
|
|
epickerArgs: {
|
|
|
|
eprom: null,
|
|
|
|
mouse: false,
|
|
|
|
target: '',
|
|
|
|
zap: false,
|
|
|
|
},
|
2017-03-05 14:25:55 +01:00
|
|
|
|
2018-04-06 22:02:35 +02:00
|
|
|
scriptlets: {},
|
2019-05-11 16:40:34 +02:00
|
|
|
|
|
|
|
cspNoInlineScript: "script-src 'unsafe-eval' * blob: data:",
|
|
|
|
cspNoScripting: 'script-src http: https:',
|
|
|
|
cspNoInlineFont: 'font-src *',
|
2019-08-11 19:55:39 +02:00
|
|
|
|
|
|
|
liveBlockingProfiles: [],
|
2019-08-19 15:00:53 +02:00
|
|
|
blockingProfileColorCache: new Map(),
|
2017-03-05 14:25:55 +01:00
|
|
|
};
|
2014-06-24 00:42:43 +02:00
|
|
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|