What should I do to make it work in greasemonkey?:
Element.prototype._attachShadow = Element.prototype.attachShadow;
Element.prototype.attachShadow = function () {
return this._attachShadow( { mode: "open" } );
};
Now, when I use this:
document.body.attachShadow({mode:"closed"}).innerHTML = "dec";
Is this bug:
Error: Permission denied to access object
What should I do to make the application use the substituted method?
EDIT (MORE INFO):
Firefox Nightly 62.0a1 (2018-06-18) (64 bity)
Greasemonkey 4.4.0
// ==UserScript==
// @name Unnamed Script 124585
// @version 1
// @grant none
// @include http://kind-clarke-ced7cb.bitballoon.com/
// ==/UserScript==
Element.prototype._attachShadow = Element.prototype.attachShadow;
Element.prototype.attachShadow = function () {
return this._attachShadow( { mode: "open" } );
};
console.log("US work");
Tested page: http://kind-clarke-ced7cb.bitballoon.com/
<div id="test" style="border: 1px solid silver;">xxx</div>
<div id="info">wait 4 sec...(so that UserScript can load itself before)</div>
<script>
setTimeout(()=>{
document.querySelector("#test").attachShadow({mode:"closed"}).innerHTML = "dec";
document.querySelector("#info").innerHTML += `<br/>run: document.querySelector("#test").attachShadow({mode:"closed"}).innerHTML = "dec";`;
}, 3000);
setTimeout(()=>{
document.querySelector("#info").innerHTML += `<br/>shadowRoot of #test is: ${(document.querySelector("#test").shadowRoot)}`;
}, 4000);
</script>
Now this substitution of the attachShadow method simply does not work.
shadowRoot of #test return null but should be [object ShadowRoot]
, because UserScript forces it.