Closed Bug 1514673 Opened 6 years ago Closed 6 years ago

A promise chain failed to handle a rejection: Argument 1 of WebExtensionPolicy.canAccessWindow is not an object. - stack: canAccessWindow@resource://gre/modules/Extension.jsm:1608:12 after bug 1498775

Categories

(WebExtensions :: General, defect)

defect
Not set
normal

Tracking

(firefox66 verified, firefox67 verified)

VERIFIED FIXED
mozilla66
Tracking Status
firefox66 --- verified
firefox67 --- verified

People

(Reporter: arai, Assigned: mixedpuppy)

References

Details

Attachments

(1 file, 1 obsolete file)

After fixing bug 1498775, the following error happens: https://treeherder.mozilla.org/#/jobs?repo=mozilla-inbound&resultStatus=testfailed%2Cbusted%2Cexception%2Crunnable&classifiedState=unclassified&revision=d3058a4b2450317636a81badc374600e913940c0&selectedJob=217378267 TEST-UNEXPECTED-FAIL | toolkit/components/extensions/test/browser/browser_ext_themes_dynamic_getCurrent.js | A promise chain failed to handle a rejection: Argument 1 of WebExtensionPolicy.canAccessWindow is not an object. - stack: canAccessWindow@resource://gre/modules/Extension.jsm:1608:12 canAccessWindow@resource://gre/modules/ExtensionCommon.jsm:453:12 getAPI/register/listener/<@chrome://browser/content/parent/ext-windows.js:76:22 https://searchfox.org/mozilla-central/rev/1a4a7745fd4a14402a0de0e9abc040724d4fcf8f/toolkit/components/extensions/Extension.jsm#1608 > class Extension extends ExtensionData { > ... > canAccessWindow(window) { > return this.policy.canAccessWindow(window); > } https://searchfox.org/mozilla-central/rev/1a4a7745fd4a14402a0de0e9abc040724d4fcf8f/toolkit/components/extensions/ExtensionCommon.jsm#453 > class BaseContext { > ... > canAccessWindow(window) { > return this.extension.canAccessWindow(window); > } https://searchfox.org/mozilla-central/rev/1a4a7745fd4a14402a0de0e9abc040724d4fcf8f/browser/components/extensions/parent/ext-windows.js#76 > this.windows = class extends ExtensionAPI { > getAPI(context) { > let {extension} = context; > > const {windowManager} = extension; > > return { > windows: { > ... > onFocusChanged: new EventManager({ > context, > name: "windows.onFocusChanged", > register: fire => { > // Keep track of the last windowId used to fire an onFocusChanged event > let lastOnFocusChangedWindowId; > > let listener = event => { > // Wait a tick to avoid firing a superfluous WINDOW_ID_NONE > // event when switching focus between two Firefox windows. > Promise.resolve().then(() => { > let window = Services.focus.activeWindow; > if (!context.canAccessWindow(window)) { possibly the activeWindow property is either null or undefined.
Blocks: 1345474
https://searchfox.org/mozilla-central/rev/1a4a7745fd4a14402a0de0e9abc040724d4fcf8f/browser/components/extensions/parent/ext-windows.js#74-84 > Promise.resolve().then(() => { > let window = Services.focus.activeWindow; > if (!context.canAccessWindow(window)) { > return; > } > let windowId = window ? windowTracker.getId(window) : Window.WINDOW_ID_NONE; > if (windowId !== lastOnFocusChangedWindowId) { > fire.async(windowId); > lastOnFocusChangedWindowId = windowId; > } > }); The issue is that, the return value of `Promise.resolve().then(...)` is not used, which results in not-reporting the unhandled rejection (which is going to be fixed by bug 1498775). Given the next line after `context.canAccessWindow` call checks the if `window` is falsy, falsy `window` seems to be expected. `context.canAccessWindow` call should be skipped in that case I guess.
I'll post a patch after some test
Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED
Tooru, sorry, I worked up a patch before I realized you actually took the bug. Since I made the patch already, I'm taking over the bug.
Assignee: arai.unmht → mixedpuppy
Tooru can you take a peak at the try in comment 6?
Flags: needinfo?(arai.unmht)
looks like, bug 1514699 (bc* failures) is not from bug 1498775 change, but just that it's discovered by this change? I filed bug 1514699 after my WIP patch for this bug applied, and got the same error: https://treeherder.mozilla.org/#/jobs?repo=try&revision=6ae720e277c240352adf7670c048743c768ae149&selectedJob=217387043 also, I saw the similar error to dt4, not yet figured out if it's pre-existing tho https://treeherder.mozilla.org/#/jobs?repo=mozilla-inbound&revision=d3058a4b2450317636a81badc374600e913940c0&duplicate_jobs=visible&searchStr=dt&selectedJob=217380038
Pushed by mixedpuppy@gmail.com: https://hg.mozilla.org/integration/autoland/rev/6267aad872ec allow WINDOW_ID_NONE in focus listener, r=rpl
Backed out changeset 6267aad872ec (Bug 1514673) for bc failures in browser/components/extensions/test/browser/test-oop-extensions/browser_ext_tabs_events.js https://treeherder.mozilla.org/#/jobs?repo=autoland&selectedJob=217710655 https://treeherder.mozilla.org/logviewer.html#/jobs?job_id=217710655&repo=autoland&lineNumber=2563
Backout by shindli@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/cd6b203426db Backed out changeset 6267aad872ec for bc failures in browser/components/extensions/test/browser/test-oop-extensions/browser_ext_tabs_events.js
Attachment #9031879 - Attachment is obsolete: true
Pushed by mixedpuppy@gmail.com: https://hg.mozilla.org/integration/autoland/rev/d0f2ead4061c allow WINDOW_ID_NONE in focus listener, r=rpl
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla66
Flags: needinfo?(arai.unmht)

Verified as fixed on latest FF66 and FF67 using the following steps(Thanks @rpl for the steps):

  1. toggle incognito mode preference by flipping "extensions.allowPrivateBrowsingByDefault" to false
  2. install the test extension from https://drive.google.com/file/d/1ZM3Qo4ltc1i5dqsEDPzwQon3iTPOFiXT/view?usp=sharing
  3. open the browser console and a private window
  4. open another unrelated application (e.g. a text editor)
  5. focus the initial firefox window and then the browser console (a couple of console messages "Received windowId ..., is it WINDOW_ID_NONDE? true/false" should be logged, and no "Argument 1 of WebExtensionPolicy.canAccessWindow is not an object." error)
  6. focus the initial firefox window and then the private window (same messages as above, and not the error message)
  7. focus the initial firefox window and then the unrelated application (e.g. the text editor, same messages as above and not the error message)
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: