javascript - open the "closed" shadowRoot created outside of my chrome extension - Stack Overflow

well google translate extension in chrome, has popup feature, it displays translation of selected word

well google translate extension in chrome, has popup feature, it displays translation of selected word instantly, I wanted to access those translations displayed by popup, but this popup element is shadowRoot("closed"), so javascript cant access its content, I red an article about that subject and author says:

But really there is nothing stopping someone executing the following JavaScript before your ponent definition. Element.prototype._attachShadow = Element.prototype.attachShadow; Element.prototype.attachShadow = function () { return this._attachShadow( { mode: "open" } ); };

Is it possible to change attachShadow method of other extension? if so where should it be executed by my extension? background_script or maybe somewhere. I think each extension has its own enviroment and I have no chane to edit their methods. I wish I'm wrong :)

well google translate extension in chrome, has popup feature, it displays translation of selected word instantly, I wanted to access those translations displayed by popup, but this popup element is shadowRoot("closed"), so javascript cant access its content, I red an article about that subject and author says:

But really there is nothing stopping someone executing the following JavaScript before your ponent definition. Element.prototype._attachShadow = Element.prototype.attachShadow; Element.prototype.attachShadow = function () { return this._attachShadow( { mode: "open" } ); };

Is it possible to change attachShadow method of other extension? if so where should it be executed by my extension? background_script or maybe somewhere. I think each extension has its own enviroment and I have no chane to edit their methods. I wish I'm wrong :)

Share Improve this question edited Mar 3, 2024 at 18:21 woxxom 74k14 gold badges156 silver badges160 bronze badges asked Dec 26, 2021 at 21:15 Nika MaisuradzeNika Maisuradze 651 gold badge2 silver badges5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

No need to override it.
There's a special method in the content script.

  • Chrome 88+:

    let shadowRoot = chrome.dom.openOrClosedShadowRoot(element);
    
  • Firefox 63:

    let shadowRoot = element.openOrClosedShadowRoot();
    
  • Combined:

    let shadowRoot = chrome.dom?.openOrClosedShadowRoot(element)
      || element.openOrClosedShadowRoot();
    

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744149302a4560571.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信