Chrome插件无法正确初始化 [英] Chrome plugin not initializing properly

查看:787
本文介绍了Chrome插件无法正确初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  {
)我试图写一个chrome插件,我用下面的清单定义了它:名称:test,
version:1.0,
background:{scripts:[background.js]},
permissions:[
tabs,http:// * / *
],
browser_action:{
name:test,
图标:[icon.png]
},
manifest_version:2
}



我的 background.js 文件如下所示:

  chrome.app.runtime.onLaunched.addListener(function(){
console.log('details',chrome.app.getDetails());
});

加载时,我在控制台上看到这个错误:

  Uncaught TypeError:无法读取未定义的属性'onLaunched'

我无法弄清为什么我没有看到正确初始化的 chrome.app.runtime



我该如何调试?

基因

UPDATE:



当我运行以下代码时:

  console.log(连接前); 
chrome.extension.onConnect.addListener(function(port){
console.log(connected);
});

我在连接前看到第一个日志输出( )但不是第二个;这是否意味着它无法连接到浏览器?

解决方案

chrome.app 未定义,因为您没有将您的扩展程序定义为应用程序。



Chrome扩展程序在清单中只能是其中的一种 file:
browser_action page_action theme ,或 app



在您的清单中,您正在定义浏览器操作。

b

请深呼吸并阅读清单文件。


I am trying to write a chrome plugin,which I defined with the following manifest:

{
  "name": "test",
  "version": "1.0",
  "background": { "scripts": ["background.js"] },
  "permissions": [
    "tabs", "http://*/*"
  ],
  "browser_action": {
    "name": "test",
    "icons": ["icon.png"]
  },
  "manifest_version": 2
}

my background.js file looks like this:

chrome.app.runtime.onLaunched.addListener(function() { 
    console.log('details', chrome.app.getDetails());
});

When it loads, I see this error on the console:

Uncaught TypeError: Cannot read property 'onLaunched' of undefined 

I can't figure out why I am not seeing a properly initialized chrome.app.runtime.

How do I debug this?

Gene

UPDATE:

When I run the following code:

console.log("before connection");
chrome.extension.onConnect.addListener(function(port) {
    console.log("connected");
});

I see the first log output (before connection) but not the second; does this mean that it fails to connect to the browser?

解决方案

chrome.app is undefined because you aren't defining your extension as an app.

Chrome extension can be only one of these in the manifest file: browser_action, page_action, theme, or app.

In your manifest you're defining an browser action.

So take a deep breath and read the documentation for the manifest file.

这篇关于Chrome插件无法正确初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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