Closed
Bug 1290157
Opened 9 years ago
Closed 8 years ago
chrome.tabs.executeScript passes the wrong arguments to its callback
Categories
(WebExtensions :: Untriaged, defect)
Tracking
(firefox50 verified, firefox51 verified)
VERIFIED
FIXED
mozilla51
People
(Reporter: sixtyten, Assigned: robwu)
References
(Blocks 1 open bug)
Details
(Keywords: addon-compat, dev-doc-complete, Whiteboard: triaged)
Attachments
(1 file)
58 bytes,
text/x-review-board-request
|
kmag
:
review+
ritu
:
approval-mozilla-beta+
|
Details |
User Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0
Build ID: 20160623154057
Steps to reproduce:
Platform: Windows 10
Version: Nightly 50.0a1 (2016-07-26)
execute the following code in the WebExtensions debugger:
chrome.tabs.executeScript(<current tab id>, { code: "'SUCCESS'" }, results => console.log(results));
Actual results:
console logged SUCCESS.
Expected results:
console should've logged ["SUCCESS"].
As documented in https://developer.chrome.com/extensions/tabs#method-executeScript, the arguments to the callback will be an array of results, not one result.
Comment 1•9 years ago
|
||
We only pass an array when `allTabs` is true. I don't think we can change this now without causing problems for existing extensions.
When you run the above snippet in Chrome, you get ["SUCCESS"], not SUCCESS.
I personally prefer the way Firefox does it, but as it is, it's incompatible with what happens in Chrome and breaks my existing extension that I am in the process of porting over. I can easily test for this - but compatibility is the point, isn't it?
Comment 3•8 years ago
|
||
querying to see what is most aligned to determine to break Fx or compat
Flags: needinfo?(amckay)
Assignee | ||
Comment 4•8 years ago
|
||
I analyzed AMO's database, and searched for tabs.executeScript calls that include an inline function that expects a parameter.
In other words, something of the form tabs.executeScript(optionalTabId, injectionDetails, function(theVariableInQuestion)
https://dxr.mozilla.org/addons/search?q=regexp%3Atabs%5C.executeScript%5C(%5B%5E)%5D%2Bfunction%5C(%5B%5E)%5D&redirect=false
- 48 results in 30 addons
- Addon 682676: Relies on Chrome's behavior (executeScript's callback parameter undefined = injection failed).
- Addon 683911: Relies on Chrome's behavior.
- Addon 686201: Relies on Chrome's behavior.
- Addon 686921: Parameter is not used, but present in commented-out code, probably because "if(!data)" does not tell whether injection failed (so the original code may rely on Chrome's behavior, but because that cannot be emulated in Firefox, the code was commented out).
- Addon 688158: Relies on Chrome's behavior.
- Addon 693060: Relies on Chrome's behavior.
- Addon 695957: Relies on Chrome's behavior.
- Addon 698451: Relies on Chrome's behavior.
All 22 other addons do not rely on the type of the parameter (so fixing this bug doesn't affect them).
None of the addons in this sample relies on Firefox's non-array type.
8 of them are relying on Chrome's array type parameter.
This investigation is not exhaustive, but based on this data, I think that we should migrate to Chrome's format. Preferably sooner than later, and uplift it to 50 and 49 before addon devs start relying on Firefox' current behavior.
Blocks: webextensions-chrome-gaps
Comment 5•8 years ago
|
||
Agreed, if we're going to do this, we should do it immediately, and uplift to 50 and then 49 at 1-week-ish intervals.
Flags: needinfo?(amckay)
Comment 6•8 years ago
|
||
Thanks for doing that analysis Rob. Agreed, let's change to chromes behaviour.
Assignee | ||
Updated•8 years ago
|
Assignee: nobody → rob
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Comment hidden (mozreview-request) |
Comment hidden (mozreview-request) |
Comment 9•8 years ago
|
||
mozreview-review |
Comment on attachment 8779226 [details]
Bug 1290157 - Always pass an array to tabs.executeScript on success
https://reviewboard.mozilla.org/r/70272/#review68158
::: browser/components/extensions/test/browser/browser_ext_tabs_executeScript.js:69
(Diff revision 2)
> browser.tabs.executeScript({
> code: "location.href;",
> runAt: "document_end",
> }).then(result => {
> - browser.test.assertTrue(typeof(result) == "string", "Result is a string");
> + browser.test.assertEq(1, result.length, "Expected callback result");
> + browser.test.assertTrue(typeof(result[0]) == "string", "Result is a string");
`assertEq("string", typeof(result), ...)`
::: browser/components/extensions/test/browser/browser_ext_tabs_executeScript.js:146
(Diff revision 2)
> browser.tabs.executeScript({
> code: "location.href;",
> frameId: frames[0].frameId,
> }).then(result => {
> + browser.test.assertEq(1, result.length, "Expected one result");
> browser.test.assertTrue(/\/file_iframe_document\.html$/.test(result), `Result for frameId[0] is correct: ${result}`);
`result[0]`
::: toolkit/components/extensions/ExtensionContent.jsm:651
(Diff revision 2)
> - return promises[0];
> + if (options.jsCode || options.js.length) {
> + // executeScript.
> + return Promise.all(promises);
> + }
> + // insertCSS / removeCSS.
> + return Promise.all(promises).then(() => {});
This can be handled on the caller side.
Comment hidden (mozreview-request) |
Comment 11•8 years ago
|
||
mozreview-review |
Comment on attachment 8779226 [details]
Bug 1290157 - Always pass an array to tabs.executeScript on success
https://reviewboard.mozilla.org/r/70272/#review68840
::: toolkit/components/extensions/ExtensionContent.jsm:646
(Diff revision 3)
> - return promises[0];
> + if (options.jsCode || options.js.length) {
> + // executeScript.
> + return Promise.all(promises);
> + }
> + // insertCSS / removeCSS.
> + return Promise.all(promises).then(() => {});
You still haven't addressed this issue.
Attachment #8779226 -
Flags: review?(kmaglione+bmo)
Assignee | ||
Comment 12•8 years ago
|
||
mozreview-review-reply |
Comment on attachment 8779226 [details]
Bug 1290157 - Always pass an array to tabs.executeScript on success
https://reviewboard.mozilla.org/r/70272/#review68158
> This can be handled on the caller side.
I'm doing it here because there is no point in passing data around that is never used anyway.
Assignee | ||
Comment 13•8 years ago
|
||
Comment on attachment 8779226 [details]
Bug 1290157 - Always pass an array to tabs.executeScript on success
See above comment.
Attachment #8779226 -
Flags: review?(kmaglione+bmo)
Comment 14•8 years ago
|
||
mozreview-review-reply |
Comment on attachment 8779226 [details]
Bug 1290157 - Always pass an array to tabs.executeScript on success
https://reviewboard.mozilla.org/r/70272/#review68158
> I'm doing it here because there is no point in passing data around that is never used anyway.
There's no harm in it either. This is much easier to follow if `insertCSS` handles discarding the return values.
Updated•8 years ago
|
Attachment #8779226 -
Flags: review?(kmaglione+bmo)
Comment hidden (mozreview-request) |
Comment 16•8 years ago
|
||
mozreview-review |
Comment on attachment 8779226 [details]
Bug 1290157 - Always pass an array to tabs.executeScript on success
https://reviewboard.mozilla.org/r/70272/#review68896
Attachment #8779226 -
Flags: review?(kmaglione+bmo) → review+
Updated•8 years ago
|
Keywords: addon-compat,
dev-doc-needed
Updated•8 years ago
|
Whiteboard: triaged
Assignee | ||
Updated•8 years ago
|
Keywords: checkin-needed
Comment 17•8 years ago
|
||
Pushed by ryanvm@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/86c39a5b482d
Always pass an array to tabs.executeScript on success r=kmag
Keywords: checkin-needed
Comment 18•8 years ago
|
||
bugherder |
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
status-firefox51:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla51
Comment 19•8 years ago
|
||
(In reply to Kris Maglione [:kmag] from comment #5)
> Agreed, if we're going to do this, we should do it immediately, and uplift
> to 50 and then 49 at 1-week-ish intervals.
Will this be uplifted to 50?
For the docs: the existing docs describe Chrome's behavior, so I suppose the docs ought to say "Before Firefox version XX, the callback is passed ... ".
Comment 20•8 years ago
|
||
Comment on attachment 8779226 [details]
Bug 1290157 - Always pass an array to tabs.executeScript on success
Approval Request Comment
[Feature/regressing bug #]: Bug 1210583
[User impact if declined]: Extensions written for the newer/expected behavior will fail to work correctly in affected browsers.
[Describe test coverage new/current, TreeHerder]: This feature is extensively tested.
[Risks and why]: Low. We weren't able to find any add-ons that rely on the former behavior, but add-ons that rely on the new behavior do exist.
[String/UUID change made/needed]: None.
Attachment #8779226 -
Flags: approval-mozilla-beta?
status-firefox50:
--- → affected
Hello there, could you please verify this issue is fixed as expected on a latest Nightly build? Thanks!
Flags: needinfo?(sixtyten)
Comment on attachment 8779226 [details]
Bug 1290157 - Always pass an array to tabs.executeScript on success
Web extensions related, Beta50+
Attachment #8779226 -
Flags: approval-mozilla-beta? → approval-mozilla-beta+
Assignee | ||
Comment 23•8 years ago
|
||
Verified fixed in Nightly (2016-09-23) on Linux, as follows:
1. Create a folder with two files:
manifest.json:
{
"name": "Manual test case for bugzil.la/1290157",
"version": "1",
"manifest_version": 2,
"background": {
"scripts": ["background.js"]
},
"browser_action": {
},
"permissions": [
"tabs",
"*://*/*"
]
}
background.js
chrome.browserAction.onClicked.addListener(function() {
chrome.tabs.executeScript({
code: '"SUCCESS"',
}, function(results) {
console.log(results);
});
});
2. Visit about:debugging, click on "Load Temporary Add-on".
3. Select the directory from step 1 and observe that a new button is added to the toolbar.
4. Visit example.com
5. Click on the add-on button.
6. Open the global JavaScript console (Ctrl-Shift-J).
Expected: Array [ "SUCCESS" ]
(In Firefox 49.0.1, I only see "SUCCESS" - sans quotes, and without the "Array" prefix)
Flags: needinfo?(sixtyten)
Comment 24•8 years ago
|
||
bugherder uplift |
Comment 25•8 years ago
|
||
I was able to reproduce the initial issue on Firefox 49.0.1 under Windows 10 64-bit.
Verified fixed on Firefox 50.0b6 (20161010144024), Firefox 51.0a2 (2016-10-12) and Firefox 52.0a1 (2016-10-11 )under Windows 10 64-bit. Array [ "SUCCESS" ] is successfully displayed in Browser Console.
Comment 26•8 years ago
|
||
I've added this to the compat notes for executeScript: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/Tabs/executeScript#Browser_compatibility.
Marking as dev-doc-complete, but let me know if you see anything else needed here.
Keywords: dev-doc-needed → dev-doc-complete
Updated•7 years ago
|
Product: Toolkit → WebExtensions
You need to log in
before you can comment on or make changes to this bug.
Description
•