Is it possible to message the dev-tools panel from within inspectedWindow.eval?

僤鯓⒐⒋嵵緔 提交于 2019-12-04 19:10:27
Xan

You said you considered using a content script.

In that case, you can raise a custom DOM event, and the content script will be able to process it.

// Content script
window.addEventListener("RebroadcastExtensionMessage", function(evt) {
  chrome.runtime.sendMessage(evt.detail);
}, false);

// Eval'd code
var message = {/* whatever */};
var event = new CustomEvent("RebroadcastExtensionMessage", {detail: message});
window.dispatchEvent(event);

The downside, of course, is that the page can listen in on those events if it so chooses as well as spoof them. If that's a serious concern, you can include nonces into event names and messages originating from dev tools. But then again, a really hostile page can override CustomEvent.. In a way, this is not a solvable problem, since anything you inspectedWindow.eval() fully shares context (and API access) with the page.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!