-
Notifications
You must be signed in to change notification settings - Fork 206
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
fix: Prevent a webpage document element to be detected as the Extension API object #153
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c8cbd6e
fix: Prevent a webpage document element to be detected as the Extensi…
rpl 57da1c3
chore: applied changes based on the last review comments
rpl a6f31b2
chore: applied a small tweak to fix a test unit failure due to the la…
rpl de4adf5
chore: added integration for API object detection in background page …
rpl 17536d2
chore: minor tweaks on tests based on last round of review comments
rpl File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
test/fixtures/detect-existing-browser-api-object/background.html
This file contains 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,20 @@ | ||
<!DOCTYPE> | ||
<html> | ||
<head> | ||
<title>Test Extension Background page</title> | ||
<meta charset="utf-8"> | ||
</head> | ||
<body> | ||
<!-- | ||
The following two DOM elements ensure that the polyfill doesn't detect the | ||
globals defined for these DOM element ids as the Extensions API objects. | ||
--> | ||
<div id="browser"></div> | ||
<div id="browser"></div> | ||
<div id="chrome"></div> | ||
|
||
<script src="copy-original-api-objects.js"></script> | ||
<script src="browser-polyfill.js"></script> | ||
<script src="background.js"></script> | ||
</body> | ||
</html> |
15 changes: 15 additions & 0 deletions
15
test/fixtures/detect-existing-browser-api-object/background.js
This file contains 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 @@ | ||
/* global originalAPIObjects */ | ||
|
||
// Register an additional message handler that always reply after | ||
// a small latency time. | ||
browser.runtime.onMessage.addListener(async (msg, sender) => { | ||
if (msg !== "test-api-object-in-background-page") { | ||
return false; | ||
} | ||
|
||
return Promise.resolve({ | ||
browserIsDefined: !!browser, | ||
chromeIsDefined: !!chrome, | ||
browserIsUnchanged: browser === originalAPIObjects.browser, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's check |
||
}); | ||
}); |
This file contains 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
2 changes: 2 additions & 0 deletions
2
test/fixtures/detect-existing-browser-api-object/copy-original-api-objects.js
This file contains 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,2 @@ | ||
// Store a copy of the references to the original API objects. | ||
const originalAPIObjects = {browser, chrome}; // eslint-disable-line no-unused-vars | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a comment that in browsers without a |
This file contains 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 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
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.
Why
return false;
? If you don't want the handler to respond, jus return void (return;
).Or make this a non-async function and call
sendResponse({ ... });
in the end.