-
Notifications
You must be signed in to change notification settings - Fork 31
Support navigation based conditional matching #1610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e7e0ac9
Add patching changes
jonathanKingston aed4fb3
Rename matchDomainFeatureSetting to matchConditionalFeatureSetting
jonathanKingston ee0ba65
Add in array matching of conditions and simplify logic to prevent err…
jonathanKingston 698d54f
PoC handle navigation centrally
jonathanKingston f5ec3ea
Fix missing pathname
jonathanKingston 9d37c04
Merge remote-tracking branch 'origin/main' into jkt/web-interventions…
jonathanKingston bbf3c5b
Add test case and inline contentfeature
jonathanKingston 7543748
Move url change to before callbacks, add testing
jonathanKingston 19519bd
Add back listener test case
jonathanKingston 310cc95
Add navigation listener, make top frame only
jonathanKingston 7d04e76
Document the listenForUrlChanges
jonathanKingston 061b06d
Simplify listening and site computation
jonathanKingston 42d6241
Add test case for fallback logic
jonathanKingston File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
injected/integration-test/test-pages/infra/config/conditional-matching.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| { | ||
| "features": { | ||
| "apiManipulation": { | ||
| "state": "enabled", | ||
| "settings": { | ||
| "apiChanges": { | ||
| "Navigator.prototype.hardwareConcurrency": { | ||
| "type": "descriptor", | ||
| "getterValue": { | ||
| "type": "number", | ||
| "value": 222 | ||
| } | ||
| } | ||
| }, | ||
| "conditionalChanges": [ | ||
| { | ||
| "condition": { | ||
| "urlPattern": "/test/*" | ||
| }, | ||
| "patchSettings": [ | ||
| { | ||
| "op": "replace", | ||
| "path": "/apiChanges/Navigator.prototype.hardwareConcurrency/getterValue/value", | ||
| "value": 333 | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| }, | ||
| "unprotectedTemporary": [] | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width"> | ||
| <title>API Interventions</title> | ||
| <link rel="stylesheet" href="../shared/style.css"> | ||
| </head> | ||
| <body> | ||
| <p><a href="../../index.html">[Home]</a></p> | ||
| <ul> | ||
| <li><a href="./pages/conditional-matching.html">Conditional matching</a> - <a href="./config/conditional-matching.json">Config</a></li> | ||
| </ul> | ||
| </body> | ||
| </html> |
48 changes: 48 additions & 0 deletions
48
injected/integration-test/test-pages/infra/pages/conditional-matching.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width"> | ||
| <title>Conditional Matching</title> | ||
| <link rel="stylesheet" href="../../shared/style.css"> | ||
| </head> | ||
| <body> | ||
| <script src="../../shared/utils.js"></script> | ||
| <p><a href="../index.html">[Infra]</a></p> | ||
|
|
||
| <p>This page verifies that APIs get modified</p> | ||
|
|
||
| <script> | ||
| test('Conditional matching', async () => { | ||
| const results = [ | ||
| { | ||
| name: "APIs changing, expecting to always match", | ||
| result: navigator.hardwareConcurrency, | ||
| expected: 222 | ||
| } | ||
| ]; | ||
|
|
||
| const newUrl = new URL(window.location.href); | ||
| newUrl.pathname = "/test/test/path"; | ||
| window.history.pushState(null, '', newUrl.href); | ||
| await new Promise(resolve => requestIdleCallback(resolve)); | ||
| results.push({ | ||
| name: "Expect URL to be changed", | ||
| result: window.location.pathname, | ||
| expected: '/test/test/path' | ||
| }) | ||
| results.push({ | ||
| name: "APIs changing, expecting to match only when the URL is correct", | ||
| result: navigator.hardwareConcurrency, | ||
| expected: 333 | ||
| }) | ||
|
|
||
| return results; | ||
| }); | ||
|
|
||
|
|
||
| // eslint-disable-next-line no-undef | ||
| renderResults(); | ||
| </script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { DDGProxy, DDGReflect, computeLimitedSiteObject } from './utils.js'; | ||
| import ContentFeature from './content-feature.js'; | ||
|
|
||
| const urlChangeListeners = new Set(); | ||
| /** | ||
| * Register a listener to be called when the URL changes. | ||
| * @param {function} listener | ||
| */ | ||
| export function registerForURLChanges(listener) { | ||
| if (urlChangeListeners.size === 0) { | ||
| listenForURLChanges(); | ||
| } | ||
| urlChangeListeners.add(listener); | ||
| } | ||
|
|
||
| function handleURLChange() { | ||
| const site = computeLimitedSiteObject(); | ||
| for (const listener of urlChangeListeners) { | ||
| listener(site); | ||
| } | ||
| } | ||
|
|
||
| function listenForURLChanges() { | ||
| const urlChangedInstance = new ContentFeature('urlChanged', {}, {}); | ||
| // single page applications don't have a DOMContentLoaded event on navigations, so | ||
| // we use proxy/reflect on history.pushState to call applyRules on page navigations | ||
| const historyMethodProxy = new DDGProxy(urlChangedInstance, History.prototype, 'pushState', { | ||
| apply(target, thisArg, args) { | ||
| const changeResult = DDGReflect.apply(target, thisArg, args); | ||
| handleURLChange(); | ||
| return changeResult; | ||
| }, | ||
| }); | ||
| historyMethodProxy.overload(); | ||
| // listen for popstate events in order to run on back/forward navigations | ||
| window.addEventListener('popstate', () => { | ||
| handleURLChange(); | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means we'll rerun rules on navigation change.