Open Bug 1824896 Opened 2 years ago Updated 6 months ago

WebExtensions scripting.executeScript(): typeof InjectionResult.error === "string" when InjectionTarget.files not found

Categories

(WebExtensions :: General, defect, P3)

Firefox 111
defect

Tracking

(Not tracked)

People

(Reporter: manikulin, Unassigned)

References

(Blocks 1 open bug)

Details

User Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/111.0

Steps to reproduce:

browser.scripting.executeScript() may return string instead of an Error object as Injection.error field if specified script is not found.

This is a follow-up of https://github.com/mdn/content/pull/25624#discussion_r1149825223

  • Load any mv3 extension having the scripting and activeTab permissions.
  • Inspect it, switch to console.
  • Switch to a regular page tab (a "file:///..." page in my case to be precise).
  • Execute in the add-on Developer Tools console:
    var [{ id: tabId }] = await browser.tabs.query({lastFocusedWindow: true, active:true})
    var result = await browser.scripting.executeScript({target: {tabId}, files: [ "not-found.js"]})
    typeof result[0].error
    Object.prototype.toString.call(result[0].error)
    result[0].error
    

Actual results:

typeof result[0].error // => "string"
Object.prototype.toString.call(result[0].error) // => "[object String]"
result[0].error // => "Unable to load script: moz-extension://adcc87c2-3c98-420a-8204-a5b2d30954cb/not-found.js"

Expected results:

typeof result[0].error // => "object"
Object.prototype.toString.call(result[0].error) // => "[object Error]"
result[0].error // => Error: Unable to load script: moz-extension://adcc87c2-3c98-420a-8204-a5b2d30954cb/not-found.js
Blocks: 1735474
Status: UNCONFIRMED → NEW
Ever confirmed: true
See Also: → 1740608

We should ideally be rejecting the whole promise if the file does not exist. Chrome does that too.

(In reply to Rob Wu [:robwu] from comment #1)

We should ideally be rejecting the whole promise if the file does not exist. Chrome does that too.

In general I agree.

What may be a mild objection is the case of multiple InjectionTarget.files when the last one succeeds despite some preceding file is missed. In some sense it may be considered similar to the https://crbug.com/1325114 issue that Chromium returns rejected promise when the extension does not have access to any of requested frameIds. Partial result may still be helpful. However while every frame is represented by an element of result array, I have no idea how to report partial failure when some file is missing.

Severity: -- → S4
Priority: -- → P3
See Also: → 1891502
You need to log in before you can comment on or make changes to this bug.