如何从devtool页面发送消息到后台页面?

时间:2016-03-28 10:57:55

标签: google-chrome-extension

我试过类似的线程但找不到任何东西。我有一个我想从devtools页面发送到后台页面的URL,以便我可以重定向当前的网页。

我研究了相关链接,但它们没有用。我可以从后台脚本获取消息到devtools,但它不适用于devtools到后台!

我可以像这样在连接上发送网址吗?

    var backgroundPageConnection = chrome.runtime.connect(
    {
    name: "panel", url : "my url"
    });

1 个答案:

答案 0 :(得分:0)

DevTools页面无法直接调用public static void main(String[] args) { HashMap<String, String> hashMap = new HashMap<String, String>(); hashMap.put("1", "adam"); hashMap.put("2", "john"); Set<String> keySet = hashMap.keySet(); System.out.println(keySet); Iterator<String> keySetIterator = keySet.iterator(); while (keySetIterator.hasNext()) { System.out.println("key is " + keySetIterator.next()); if (keySetIterator.next() == null || keySetIterator.next() == "" || keySetIterator.next().isEmpty()) { System.out.println("Key Is Empty or null"); } else { //String Key=keySetIterator.next(); System.out.println("value is " + hashMap.get(keySetIterator.next())); } } } 。您必须使用inspectedWindow.tabId属性检索已检查窗口选项卡的ID,并向后台页面发送消息以从DevTools页面注入内容脚本。

tabs.executeScript

在后台页面中,调用//return the same id the same time var data = { inspectedWindow: { tabId: 1 } }; data.__setTabId = function(id) { data.inspectedWindow.tabId = id; }; 注入脚本。

tabs.executeScript

请检查此documentation