userScriptOptions should allow 'undefined' value
Categories
(WebExtensions :: General, defect, P5)
Tracking
(Not tracked)
People
(Reporter: erosman, Unassigned)
References
Details
Setting undefined as a value causes error.
STR
const options = {
a: true
};
const scriptObj = await browser.contentScripts.register({
matches: ["*://*.org/*"],
js: [{file: "/content_scripts/example.js"}],
scriptMetadata: {
a: options.a,
b: options.b // undefined
}
});
Error
Type error for parameter userScriptOptions (Error processing scriptMetadata: Value
must either: be a null value, be a number value, be a string value, be a boolean,
be an array value, .name must () => {
let array = Array.from(choices, forceString);
let n = array.length - 1;
array[n] = `or ${array[n]}`;
return `must either [${array.join(", ")}]`;
}, .resource must () => {
let array = Array.from(choices, forceString);
let n = array.length - 1;
array[n] = `or ${array[n]}`;
return `must either [${array.join(", ")}]`;
}, .storage must () => {
let array = Array.from(choices, forceString);
let n = array.length - 1;
array[n] = `or ${array[n]}`;
return `must either [${array.join(", ")}]`;
}, .injectInto must () => {
let array = Array.from(choices, forceString);
let n = array.length - 1;
array[n] = `or ${array[n]}`;
return `must either [${array.join(", ")}]`;
}, or .disableSyncGM must () => {
let array = Array.from(choices, forceString);
let n = array.length - 1;
array[n] = `or ${array[n]}`;
return `must either [${array.join(", ")}]`;
}) for userScripts.register.
Suggestions
undefinedshould be allowed as a value- The error notice should also list
objectas an allowed value - The error without the JS code would be easier to read
Comment 1•4 years ago
|
||
Side note: the very verbose weird-looking error message is a known bug: bug 1689733.
Comment 2•4 years ago
|
||
So this is because scriptMetadata is defined as PlainJSONValue which is itself defined like so:
https://searchfox.org/mozilla-central/rev/afbff3f3ae/toolkit/components/extensions/schemas/extension_types.json#136
The reason is that undefined values can't actually be define as JSON:
JSON.stringify(undefine) === undefined // not a string!
JSON.stringify({a: undefined}) === "{}" // an empty object.
I guess we could update our schemas to include allow undefined for array and property values, but I don't even believe our Schemas.jsm allows for an undefined base type.
Also, we probably worth aligning the new scripting API args type, since it should use JSON under the hood as well:
https://searchfox.org/mozilla-central/rev/afbff3f3ae/toolkit/components/extensions/schemas/scripting.json#34
Comment 3•4 years ago
|
||
The severity field is not set for this bug.
:mixedpuppy, could you have a look please?
For more information, please visit auto_nag documentation.
Updated•4 years ago
|
Updated•4 years ago
|
Description
•