内容脚本没有对contextmenu chrome扩展的响应 [英] No response from content script for contextmenu chrome extension

查看:114
本文介绍了内容脚本没有对contextmenu chrome扩展的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了用于上下文菜单的chrome扩展,并且它已经工作。在google chrome改变了新的API之后,我的扩展程序无法工作。我看到文档需要更改弃用的API。但没有运气!
这里是文件,

manifest.json



<$ p $ {
manifest_version:2,
name:ClickRight Plugin,
version:1.0,
description :Chrome浏览器的Clickright工具,
permissions:[contextMenus,tabs,https://www.gmail.com],
content_scripts:[
{
匹配:[
http:// * / *,
https:// * / *
],
js:[chromeplug.js]
}
],
background:
{
page:background.html


background.html



包含两个脚本,clickright.js和chromeplug.js


$ b chromeplug.js

  chrome.extension.onRequest.addListener(function(request,sender,sendResponse){
if(request.method == getHtml){
..
sendResponse({key:value});});
chrome.contextMenus.create({
title:Trace CAL Log,
contexts:[page,selection]
});
chrome.contextMenus.onClicked.addListener(function()
{
chrome.tabs.query({
active:true,
currentWindow:true},
函数(标签){
chrome.tabs.sendMessage(标签[0] .id,{方法:getHtml},函数(响应){
var id = response.key;
getChromeLogs(id,tabs [0] .url);
});
});

clickright.js

getChromeLogs(LogId,URL){}



上下文菜单没有任何反应!猜猜我已经包含了所有必要的API。将API放入文件中可能是错误的。
在此先感谢!

解决方案


I have already developed chrome extension for context menu and it worked.After the change over of new API by google chrome,my extension is not working.I saw the documents need to change the deprecated API. But no luck! Here are the files,

manifest.json

    {  
    "manifest_version": 2,  
    "name": "ClickRight Plugin",  
    "version": "1.0",  
    "description": "Clickright utility for Chrome Browser",  
    "permissions":["contextMenus","tabs","https://www.gmail.com"],  
    "content_scripts" : [  
     {  
    "matches" : [  
    "http://*/*",  
    "https://*/*"  
    ],  
    "js" : ["chromeplug.js"]  
    }  
    ],  
    "background":  
    {  
    "page":"background.html"  
    }  
    }  

background.html

Included two scripts, clickright.js and chromeplug.js

chromeplug.js

chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {  
if (request.method == "getHtml") {  
..   
sendResponse({key:value});});  
chrome.contextMenus.create({  
"title": "Trace CAL Log",  
"contexts": ["page", "selection"]  
});  
chrome.contextMenus.onClicked.addListener(function()  
{  
chrome.tabs.query({  
active: true,  
currentWindow: true},  
function(tabs) {  
chrome.tabs.sendMessage(tabs[0].id,{method:"getHtml"}, function(response) {  
var id=response.key;  
getChromeLogs(id,tabs[0].url);  
});  
});  

clickright.js
getChromeLogs(LogId,URL){}

On clicking the context menu nothing happens!Guess I have included all neccessary API. May be wrong with the placing of API in files. Thanks in Advance!

解决方案

It looks like chrome.contextMenus.create should go into background.js, not content script.

这篇关于内容脚本没有对contextmenu chrome扩展的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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