Falsey userScriptOptions.scriptMetadata are not available

VERIFIED FIXED in Firefox 64

Status

defect
P5
normal
VERIFIED FIXED
10 months ago
9 months ago

People

(Reporter: robwu, Assigned: robwu)

Tracking

unspecified
mozilla64
Dependency tree / graph

Firefox Tracking Flags

(firefox64 fixed, firefox65 verified)

Details

Attachments

(2 attachments)

If scriptMetadata is falsey (false, 0, "", null, undefined), then the metadata is always undefined.

STR:
1. Load attached extension in Nightly (including patch for bug 1437864).
2. Visit example.com

Expected:
- "Got expected data: 0"

Actual:
- "Unexpected metadata, expected 0, got undefined"

This is caused by the following:
https://searchfox.org/mozilla-central/rev/dd965445ec47fbf3cee566eff93b301666bda0e1/toolkit/components/extensions/ExtensionContent.jsm#650-651
    const clonedMetadata = scriptMetadata ?
            Cu.cloneInto(scriptMetadata, apiScope) : undefined;

How about just declaring clonedMetadata and then lazily cloning the metadata when needed? If the metadata is a large, rarely used object, then that would bring performance benefits.
Priority: -- → P5
Assignee: nobody → rob
Status: NEW → ASSIGNED
This also adds new test coverage for the previously untested features:
- "file" in "js" param to userScripts.register works.
- "allFrames" set to true in userScripts.register works.
- scriptMetadata accepts primitive values, and in particular falsey
  values in particular (= bug 1491397 ).
 - scriptMetadata is the same object in all API script calls.
Pushed by rob@robwu.nl:
https://hg.mozilla.org/integration/autoland/rev/84ceb42728e4
Correctly forward falsey scriptMetadata in userScripts API r=rpl
https://hg.mozilla.org/mozilla-central/rev/84ceb42728e4
Status: ASSIGNED → RESOLVED
Closed: 9 months ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla64
Depends on: 1499363
Thank you for the test extension and STR. 
Validated the fix as per expected results from the description using the provided extension on: latest Nightly: 65.0a1 running on Windows 10 x64 and Nightly on Ubuntu 18.04.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.