Open Bug 1764677 Opened 2 years ago Updated 2 years ago

FormData.entries() iterator is not iterable in extension content script

Categories

(WebExtensions :: Untriaged, defect, P3)

Firefox 99
defect

Tracking

(firefox99 affected, firefox100 affected, firefox101 affected)

Tracking Status
firefox99 --- affected
firefox100 --- affected
firefox101 --- affected

People

(Reporter: kevin.zun, Unassigned)

References

(Depends on 1 open bug)

Details

Attachments

(1 file)

Steps to reproduce:

Created an extension with this content script:

let f = new FormData();
f.append('foo', 'bar');
try {
    console.log([...f.entries()]);
} catch (err) {
    console.error(err);
}

Actual results:

I got a type error

TypeError: f.entries() is not iterable
    <anonymous> moz-extension://1a7245f5-d90c-43b2-b806-bd9e6536d54d/content.js:4

Expected results:

Log [['foo', 'bar']] to the console, no error.

The Bugbug bot thinks this bug should belong to the 'WebExtensions::Untriaged' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Product: Firefox → WebExtensions

Hello,

I reproduced the issue on the latest Nightly (101.0a1/20220417212536), Beta (100.0b7/20220417185951) and Release (99.0.1/20220411174855) under Windows 10 x64 and Ubuntu 16.04 LTS.

After loading the extension via about:debugging, accessing a page declared in the manifest.json file for the content script match, logged the error from comment 0 in the console.

For further details, see the attached screenshot.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Attached image 2022-04-18_10h33_35.png

The severity field is not set for this bug.
:mixedpuppy, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(mixedpuppy)

This specific error happens because the Symbol.iterator property is apparently hidden when an object is wrapped by a XrayWrapper.

Run the following from a content script to see the difference:

{
  let entries = new FormData().entries();
  console.log(entries[Symbol.iterator]);
    // = undefined
  console.log(entries.wrappedJSObject[Symbol.iterator]);
    // = function Symbol.iterator()
}

FormData is an iterable according to FormData.webidl, so I would expect any generated standard methods to be defined.

I looked up a random other iterator, new Headers().entries()[Symbol.iterator] and was initially surprised that it did expose an iterator,
and then I recalled that it's because the content script sandbox includes its own Headers definition (the "fetch" export in the content script sandbox triggers the inclusion of Headers in Sandbox.cpp).

This is basically a dupe of bug 1023984.

Severity: -- → S4
Depends on: 1023984
Flags: needinfo?(mixedpuppy)
Priority: -- → P3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: