问题描述
FF 84.0.2,通用 4.10.0
...
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")
...
控制台输出:
...
DOC CREATED
DOMException: The operation is insecure.
脚本适用于 Tampermonkey。
解决方法
从 answer to DOM parsing in JavaScript 那里得到了解决方案:
...
const doc = document.implementation.createHTMLDocument('http://www.w3.org/1999/xhtml','html');
doc.documentElement.innerHTML = page.responseText
...
代替:
...
const doc = document.implementation.createHTMLDocument('http://www.w3.org/1999/xhtml','html');
doc.open()
doc.write( page.responseText )
...