Got a solution from an answer to DOM parsing in JavaScript:
...
const doc = document.implementation.createHTMLDocument('http://www.w3.org/1999/xhtml', 'html');
doc.documentElement.innerHTML = page.responseText
...
instead of:
...
const doc = document.implementation.createHTMLDocument('http://www.w3.org/1999/xhtml', 'html');
doc.open()
doc.write( page.responseText )
...
FF 84.0.2, GM 4.10.0
The code can be seen at GitLab. The relevant part is:
...
const doc = document.implementation.createHTMLDocument('http://www.w3.org/1999/xhtml', 'html');
console.debug("DOC CREATED")
doc.open() // <-- with GM: DOMException: The operation is insecure.
console.debug("DOC OPENED")
...
Console output:
...
DOC CREATED
DOMException: The operation is insecure.
Script works with Tampermonkey.
Tampermonkey runs in page context whereas GM4 runs in a true sandbox. You’ll need to use wrappedJSObject and exportFunction for this, see
@wOxxOm Thanks for the info. If I use
@wOxxOm I read the doc for the two, property and function. It refers to content scripts vs. page scripts. Unfortunately I’m not that deep into JS to see how this can help me here.
Sandbox of GM4 is like a content script whereas document.implementation refers to the page script context, I guess. BTW why do you use this super arcane method at all, why not insertAdjacentHTML?
If doctype is the same as the current document’s you can probably use DOMParser and replace document.documentElement with the new one.