Skip to content

Commit 9bb310b

Browse files
committed
AG-30145 && AG-30144: fixed ignoring all cosmetic rules for Opera
Merge in ADGUARD-FILTERS/tsurlfilter from fix/AG-30145 to master Squashed commit of the following: commit 6f0475d Author: Dmitriy Seregin <[email protected]> Date: Tue Feb 6 14:04:39 2024 +0300 AG-30145 && AG-30144: fixed ignoring all cosmetic rules for Opera
1 parent e27098b commit 9bb310b

File tree

6 files changed

+60
-34
lines changed

6 files changed

+60
-34
lines changed

packages/tswebextension/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
<!-- TODO: manually add compare links for version to the end of the file -->
99
<!-- e.g. [0.1.2]: https://github.com/AdguardTeam/tsurlfilter/compare/tswebextension-v0.1.1...tswebextension-v0.1.2 -->
1010

11+
## [1.0.11] - 2024-02-06
12+
13+
### Fixed
14+
- Incorrect handling hook `webNavigation.onCommitted` for Opera with force
15+
recalculating matching result.
16+
- Correct export of `EXTENDED_CSS_VERSION` for mv2 version.
17+
1118
## [1.0.10] - 2024-01-27
1219

1320
### Fixed

packages/tswebextension/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@adguard/tswebextension",
3-
"version": "1.0.10",
3+
"version": "1.0.11",
44
"description": "This is a TypeScript library that implements AdGuard's extension API",
55
"main": "dist/index.js",
66
"typings": "dist/types/src/lib/mv2/background/index.d.ts",

packages/tswebextension/rollup.config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ const assistantInjectScriptConfig = {
211211
],
212212
};
213213

214+
// TODO: Remove index files from 'src/lib', 'src/lib/mv2', 'src/lib/mv3' because
215+
// they are not participating in the build process and not specified as entry points.
214216
export default [
215217
backgroundMv2Config,
216218
backgroundMv3Config,

packages/tswebextension/src/lib/mv2/background/index.ts

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ export {
66
NetworkRuleOption,
77
} from '@adguard/tsurlfilter';
88

9+
// Re-export needed to print libraries version in extension popup.
10+
// NOTE: Do not export anything from extended-css in MV3 environment to prevent
11+
// environment runtime errors, like call window.console, which is not available
12+
// in the service worker in MV3.
13+
export { EXTENDED_CSS_VERSION } from '@adguard/extended-css';
14+
915
export * from './api';
1016
export * from './app';
1117
export * from './ext-session-storage';

packages/tswebextension/src/lib/mv2/background/web-request-api.ts

+44-27
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,9 @@ export class WebRequestApi {
230230
RequestEvents.onCompleted.addListener(WebRequestApi.onCompleted);
231231

232232
// browser.webNavigation Events
233+
// Note: We need to force set matching result in Opera before run `WebRequestApi.onCommitted`
234+
// TODO: remove this when Opera bug is fixed.
235+
browser.webNavigation.onCommitted.addListener(WebRequestApi.onCommittedOperaHook);
233236
browser.webNavigation.onCommitted.addListener(WebRequestApi.onCommitted);
234237
browser.webNavigation.onDOMContentLoaded.addListener(WebRequestApi.onDomContentLoaded);
235238
browser.webNavigation.onCompleted.addListener(WebRequestApi.deleteFrameContext);
@@ -693,33 +696,6 @@ export class WebRequestApi {
693696
url,
694697
} = details;
695698

696-
/**
697-
* There is Opera bug that prevents firing WebRequest events for document and subdocument requests.
698-
* We now handle this by checking if matching result exists for main frame and if not - we create it.
699-
*
700-
* TODO remove this when Opera bug is fixed.
701-
*/
702-
if (isOpera && frameId === MAIN_FRAME_ID) {
703-
const tabContext = tabsApi.getTabContext(tabId);
704-
if (!tabContext) {
705-
return;
706-
}
707-
708-
const frame = tabContext.frames.get(frameId);
709-
if (!frame || frame.matchingResult) {
710-
return;
711-
}
712-
713-
const matchingResult = engineApi.matchRequest({
714-
requestUrl: url,
715-
frameUrl: url,
716-
requestType: RequestType.Document,
717-
frameRule: tabContext.mainFrameRule,
718-
});
719-
720-
frame.matchingResult = matchingResult;
721-
}
722-
723699
WebRequestApi.injectCosmetic({
724700
frameId,
725701
tabId,
@@ -877,4 +853,45 @@ export class WebRequestApi {
877853
*/
878854
setTimeout(() => tabContext.frames.delete(frameId), FRAME_DELETION_TIMEOUT);
879855
}
856+
857+
/**
858+
* On committed web navigation event handler only for Opera.
859+
*
860+
* There is Opera bug that prevents firing WebRequest events for document
861+
* and subdocument requests.
862+
* We now handle this by checking if matching result exists for main frame
863+
* and if not - we force create it.
864+
*
865+
* TODO: remove this when Opera bug is fixed.
866+
*
867+
* @param details Event details.
868+
*/
869+
private static onCommittedOperaHook(details: WebNavigation.OnCommittedDetailsType): void {
870+
const {
871+
frameId,
872+
tabId,
873+
url,
874+
} = details;
875+
876+
if (isOpera && frameId === MAIN_FRAME_ID) {
877+
const tabContext = tabsApi.getTabContext(tabId);
878+
if (!tabContext) {
879+
return;
880+
}
881+
882+
const frame = tabContext.frames.get(frameId);
883+
if (!frame || frame.matchingResult) {
884+
return;
885+
}
886+
887+
const matchingResult = engineApi.matchRequest({
888+
requestUrl: url,
889+
frameUrl: url,
890+
requestType: RequestType.Document,
891+
frameRule: tabContext.mainFrameRule,
892+
});
893+
894+
frame.matchingResult = matchingResult;
895+
}
896+
}
880897
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
11
export * from './background';
22
export * from './content-script';
3-
4-
// Needed to print libraries version in extension popup.
5-
// NOTE: Do not export anything from extended-css in MV3 environment to prevent
6-
// environment runtime errors, like call window.console, which is not available
7-
// in the service worker in MV3.
8-
export { EXTENDED_CSS_VERSION } from '@adguard/extended-css';

0 commit comments

Comments
 (0)