在chrome扩展中传递同步消息? [英] Synchronous message passing in chrome extensions?

查看:235
本文介绍了在chrome扩展中传递同步消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图阻止脚本文件在用户定义的网站上加载。要阻止脚本文件,我在内容脚本中使用 beforeload事件 event.preventDefault(); 只要我已经知道网站列表。我的问题是我不提前知道网站列表,所以要获取网站列表,我正在向后台页面发送请求,但响应是异步的并且不可用。

I'm trying to block a script file from loading on user defined websites. To block a script file I'm using beforeload event and event.preventDefault(); in content script which works fine as long as I already know website list. My problem is I don't know website list in advance, so to get the website list I'm sending a request to background page but response is asynchronous and unusable.

是否有任何同步邮件在Chrome扩展程序中传递,我可能在Google的文档中遗漏了?

Is there any synchronous message passing in Chrome Extensions that I possibly missed in Google's docs?

// my (simplified) code from content script:
document.addEventListener("beforeload", function(event)
{
  chrome.extension.sendRequest({fnc:"is_owner"}, function(response)
  {
    // asynchronous response is not usable because
    // all scripts have already been loaded
    if (response.is_owner) event.preventDefault();
  });
}, true);


推荐答案

很遗憾没有。有关于缺少同步消息传递的错误报告,也许如果有足够多的人出演,他们会做点什么。

Unfortunately there isn't. There is a bug report opened about lack of synchronous message passing, maybe if enough people star it they will do something about it.

这篇关于在chrome扩展中传递同步消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆