-
Notifications
You must be signed in to change notification settings - Fork 343
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: Fixed Chrome Not Opening Extensions Pages provided in URL #2321
base: master
Are you sure you want to change the base?
Conversation
Do you need anything else from me to proceed? I posted a very brief comment in reply to your question at #1979 (comment). It does answer your question, but I can imagine if some more detail is needed to understand my reply. |
Yes, I appreciate if you can point in code where I should add the call so that bg.js extension can successfully open the extensions tab as you described in your comment. I couldn't figure it out and I tried in a few different places in code to no avail. |
If your goal is to use the WebSocket to transmit the message, then you'll have to send a message once the manager extension has connected. Here is an example of a snippet that connects: https://github.com/mozilla/web-ext/blob/6.4.0/src/extension-runners/chromium.js#L147 You would have to send the message once (not on every connect), to prevent the extension from opening tabs again when the WebSocket connection is temporarily interrupted for some reason. For the current requirements, a simpler alternative is to hard-code the startup URL in the source of the manager extension. After all, the URLs are known when the extension is generated, and they need to be opened only once. To implement this approach, you'd need to pass the list of URLs to https://github.com/mozilla/web-ext/blob/6.4.0/src/extension-runners/chromium.js#L154 and write it to the generated bg.js To make sure that the tabs are opened only once, use In your current patch you're also filtering on |
I have now updated the PR with the second approach as suggested by you, eg hard-coding the startup URL in the source of the manager extension. I have also tested it with some different URL combinations and it seems to be working. Please check it out and let me know if there's anything that should be improved. Also, there are 4 failing checks for my PR which I have no idea what they relate to. So if you think the fix is good to be merged I'd appreciate if you could advise me how to fix the failing checks :) |
The test failures are linting issues. Run This is the output of circleci:
|
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.
Please address the implementation issues below (and also check that eslint
passes), and add a unit test that verifies the expected parameters and opened tabs in https://github.com/mozilla/web-ext/blob/master/tests/unit/test-extension-runners/test.chromium.js.
You'd have to verify that the expected args are present, and that the special URLs are in the generated helper extension.
src/extension-runners/chromium.js
Outdated
// Remove URLs starting with chrome:// from startingUrls and let bg.js open them instead | ||
for (let i = 0; i < startingUrls.length; i++) { | ||
if (startingUrls[i].toLowerCase().startsWith('chrome://')) { | ||
specialStartingUrls += startingUrls[i] + " " |
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.
The URLs should be appended to an array, not to a string.
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.
Thanks for the feedback. I had a hard time with template literals and arrays that's why I used string with spaces, but JSON.stringify() solves both this problem and potential code injection issue you mentioned nicely!
src/extension-runners/chromium.js
Outdated
for (let i = 0; i < startingUrls.length; i++) { | ||
if (startingUrls[i].toLowerCase().startsWith('chrome://')) { | ||
specialStartingUrls += startingUrls[i] + " " | ||
startingUrls.splice(i, 1) |
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.
By removing the element during the iteration, you'll end up skipping URLs.
For example:
[
"chrome://extensions",
"chrome://version"
]
At i=0
, "chrome://extensions"
would be appended to the list of start URLs.
But due to the startingUrls.splice(i, 1)
call, the array will be ["chrome://version"]
.
At the next iteration, i=1
, which would result in "chrome://version"
to be skipped.
To fix this, you could iterate over the URLs in reverse order and prepend the URLs to the specialStartingUrls
list. Then .splice(i, 1)
wouldn't be an issue any more.
src/extension-runners/chromium.js
Outdated
|
||
if (${specialStartingUrls.length} > 0) | ||
{ | ||
const chromeTabList = "${specialStartingUrls}".trim().split(" ") |
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.
Serialize the list of URLs with ${JSON.stringify(specialStartingUrls)}
instead of splitting by strings. Otherwise, if the URL contains a "
, this could be abused to execute code in the context of the helper extension. That's problematic.
src/extension-runners/chromium.js
Outdated
chromeTabList.forEach(url => { | ||
chrome.tabs.create({ url }); | ||
}); | ||
} |
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.
Whitespace is off, please fix this.
Codecov Report
@@ Coverage Diff @@
## master #2321 +/- ##
=======================================
Coverage 99.88% 99.88%
=======================================
Files 32 32
Lines 1699 1707 +8
=======================================
+ Hits 1697 1705 +8
Misses 2 2
Continue to review full report at Codecov.
|
Thanks for your feedback @Rob--W. I have now resolved the issues you mentioned and have also added a unit test to both check for presence of special URLs in generated script, and also lack of them in the args list sent to chrome. One issue I encountered during running existing unit tests was with the ordering of arguments being pushed to |
The code duplication is really unfortunate. Can you think of a way to implement the functionality without duplication? |
Well yes the easiest way to remove code duplication and keeping the functionality is to make a small change to 2 unit tests by shifting around the list of arguments that are being asserted. I have updated the PR with the suggested fix. Is that something that is acceptable or I should not change the existing unit tests at all? |
Hi @Rob--W Just wondering if you've had time to review this? |
Unfortunately I did not. I'll try to get back to you next week. |
This PR seems to be abandoned. I need the functionality, so I have continued it in the link below, preserving the original work here and adding a small enhancement to it. |
No description provided.