相关疑难解决方法(0)

Chrome扩展程序sendMessage错误从内容脚本到背景html

我刚刚将我的chrome扩展更新为json版本2,并且我试图让我的扩展再次工作.问题是sendRequest一路贬值.所以我将代码从https://developer.chrome.com/extensions/messaging.html复制 到我的脚本中并将其修改为我自己的变量名称,但它不起作用.

那么我回去并输入原始代码,它仍然无法正常工作.我已经阅读了多个相似的问题[并希望这不会被复制,因为它们都不是我的情况].

manifest.json的:

{
   "background": {
        "page": "background.html"
        },
    ... ... ...
   "content_scripts": [ {
      "css": [ "style.css" ],
      "js": [ "jq.js", "script.js" ],
      "matches": [ "http://*.craigslist.org/*/*.htm*" ]
   } ],
   ... ... ...
   "permissions": [ "tabs", "http://*.craigslist.org/*/*.htm*" ],
   "manifest_version": 2,
   "update_url": "http://clients2.google.com/service/update2/crx",
   "version": "3.0"
}
Run Code Online (Sandbox Code Playgroud)

background.html:

<html>
<script type='text/javascript'>
   chrome.runtime.onMessage.addListener(
  function(request, sender, sendResponse) {
    console.log(sender.tab ?
                "from a content script:" + sender.tab.url :
                "from the extension");
    if (request.greeting == "hello")
      sendResponse({farewell: "goodbye"});
  });
    });
</script>
</html>
Run Code Online (Sandbox Code Playgroud)

的script.js: …

google-chrome-extension

10
推荐指数
1
解决办法
1万
查看次数

在Chrome扩展程序中获取JSON

我的chrome扩展程序存在小问题.

我只是想从另一台服务器获取一个JSON数组.但是清单2不允许我这样做.我试过指定content_security_policy,但JSON数组存储在没有SSL证书的服务器上.

那么,如果不使用清单1,我该怎么办?

javascript ajax json google-chrome-extension content-security-policy

9
推荐指数
1
解决办法
1万
查看次数

Chrome扩展程序:端口错误:无法建立连接.接收端不存在.

尝试在我的内容和后台脚本之间进行通信时,我收到以下错误:

Port error: Could not establish connection. Receiving end does not exist.
Error in event handler for 'undefined': Cannot read property 'message' of undefined       
TypeError: Cannot read property 'message' of undefined
Run Code Online (Sandbox Code Playgroud)

background.js

function onRequest(request, sender, callbackFunction) {
    console.log("Me (BS) became this Message:" + request.message);
    sendResponse({message: request.message})
};
chrome.extension.onRequest.addListener(onRequest);
Run Code Online (Sandbox Code Playgroud)

streamcloud.js

function contactBackground(nachricht){
    chrome.extension.sendMessage({message: nachricht}, function(response) {
        console.log("The Background Script got the following Message: " + response.message);
    });
}
Run Code Online (Sandbox Code Playgroud)

和我的manifest.json

{
  "name": "InstantWatch - Dev",
  "manifest_version": 2,
  "version": "0.7",
  "permissions": ["tabs", …
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome google-chrome-extension

7
推荐指数
1
解决办法
3万
查看次数

chrome.contextMenus.create不起作用

我尝试创建一个简单的chrome扩展,在chrome的上下文菜单中添加一个选项.

这是我的manifest.json

{
   "manifest_version": 2,
   "background": "background.html",
   "description": "Add a context menu item to search for selected text at Google Maps.",
   "icons": {
      "16": "icon16.png"
   },
   "name": "Google Maps Right Click",
   "permissions": [ "contextMenus", "tabs" ],
   "version": "1.0"
}
Run Code Online (Sandbox Code Playgroud)

在这里我的background.html:

<script>

function searchgooglemaps(info)
{
 var searchstring = info.selectionText;
 chrome.tabs.create({url: "http://maps.google.com/maps?q=" + searchstring})
}

chrome.contextMenus.create({title: "Search Google Maps", contexts:["selection"], onclick: searchgooglemaps});

</script>
Run Code Online (Sandbox Code Playgroud)

但是,当我加载扩展程序并右键单击某个选项时,"搜索Google地图"按钮不会出现,我不明白为什么......

预先感谢您的帮助.

google-chrome-extension

6
推荐指数
1
解决办法
5283
查看次数

Chrome扩展程序与背景页面不使用清单版本2

我有一个简单的Chrome扩展程序,在Google Chrome中显示一个小图标.点击后,它会加载我网站的搜索页面,该页面会将您重定向到正确的页面.

https://chrome.google.com/webstore/detail/w3patrol-watch-over-any-w/addcgpijdjacmndaadfgcpbfinagiplm是扩展程序.

现在,谷歌迫使我更新到清单版本2,而不是1.但这打破了我的工作扩展.

manifest.json我添加了manifest_version 2,但从那时起,当我点击它时,图标不再起作用了.

{
   "background": {
    "page": "background.html"
    },
   "browser_action": {
      "default_icon": "icon19.png",
      "default_title": "__MSG_default_title__"
   },
   "default_locale": "en",
   "description": "__MSG_description__",
   "icons": {
      "128": "icon128.png",
      "19": "icon19.png",
      "48": "icon48.png"
   },
   "name": "__MSG_name__",
   "permissions": [ "tabs", "http://*.w3patrol.com/" ],
   "update_url": "http://clients2.google.com/service/update2/crx",
   "version": "1.0",
   "manifest_version": 2
}
Run Code Online (Sandbox Code Playgroud)

这是background.html

<script type="text/javascript">
chrome.browserAction.onClicked.addListener(function(tab) {
    chrome.tabs.getSelected(null,function(tab) {
        chrome.tabs.create( { url: "http://w3patrol.com/search.php?q=" +tab.url } );
    });
});

</script>
Run Code Online (Sandbox Code Playgroud)

我需要添加/更改以使其与清单版本2一起使用?

html javascript google-chrome google-chrome-extension

2
推荐指数
1
解决办法
7958
查看次数