Remote translation: Don't use wantGlobalProperties

Not necessary - just use the properties we inherit from contentWindow. This
fixes the DOMParser constructor, which fails if called without a window context
from a non-system principal.

https://forums.zotero.org/discussion/105163/zotero-7-doi-translator-broken-in-scaffold
This commit is contained in:
Abe Jellinek 2023-05-23 22:30:24 +03:00
parent fd6ea99967
commit caa1036da2
2 changed files with 25 additions and 24 deletions

View file

@ -261,30 +261,6 @@ class TranslationChild extends JSWindowActorChild {
*/
_loadTranslationFramework(schemaJSON, dateFormatsJSON) {
let sandbox = new Cu.Sandbox(this.contentWindow, {
wantGlobalProperties: [
"atob",
"btoa",
"Blob",
"crypto",
"CSS",
"CSSRule",
"Document",
"DOMParser",
"DOMTokenList",
"Element",
"Event",
"fetch",
"FormData",
"Headers",
"Node",
"NodeFilter",
"TextDecoder",
"TextEncoder",
"URL",
"URLSearchParams",
"Window",
"XMLHttpRequest"
],
sandboxPrototype: this.contentWindow
});

View file

@ -134,5 +134,30 @@ describe("RemoteTranslate", function () {
HiddenBrowser.destroy(browser);
translate.dispose();
});
it("should support DOMParser", async function () {
let domParserDummy = buildDummyTranslator('web', `
function detectWeb() {
return "book";
}
function doWeb() {
let item = new Zotero.Item("book");
item.title = new DOMParser().parseFromString("<body>content</body>", "text/html").body.textContent;
item.complete();
}
`);
let translate = new RemoteTranslate();
let browser = await HiddenBrowser.create(getTestDataUrl('test.html'));
await translate.setBrowser(browser);
translate.setTranslator(domParserDummy);
let items = await translate.translate({ libraryID: false });
assert.equal(items[0].title, 'content');
HiddenBrowser.destroy(browser);
translate.dispose();
});
});
});