简体   繁体   English

制作 manifest.json 文件时 Chrome 扩展程序错误

[英]Chrome extension error while making manifest.json file

Hi i am trying to make a manifest.json file which has chrome.cookies permissions which i think is an api.嗨,我正在尝试制作一个 manifest.json 文件,该文件具有 chrome.cookies 权限,我认为这是一个 api。

i tried to upload this code我尝试上传此代码

{
    "manifest_version" : 2,
    "name" : "coding train extension",
    "version" : "0.001",
    "host_permissions":[
        "*://*.google.com"
    ],
    "permissions":[
        "cookies"
    ],
    "content_scripts":  [
        {
            "matches": [
                "<all_urls>"
            ],
            "js": ["content.js"]
        }
    ]
}

The code loaded successfully but got an error代码加载成功但出现错误

在此处输入图片说明

what am i doing wrong?我究竟做错了什么?

Chrome extension must have exactly one manifest.json file, which is where you configure things such as name, description, permissions etc. See full guide to extension manifest for details, but I will walk you through what you have provided, to resolve the issues. Chrome 扩展程序必须只有一个 manifest.json 文件,您可以在其中配置名称、描述、权限等内容。有关详细信息,请参阅扩展程序清单的完整指南,但我将引导您完成您提供的内容,以解决问题.

manifest_version manifest_version

Chrome extension developers are currently (Oct 2021) undergoing a transition period, moving from manifest version 2 to version 3 . Chrome 扩展程序开发人员目前(2021 年 10 月)正在经历一个过渡期,从清单版本2转移到版本3 This transition introduces changes in how to construct a manifest (among other things), so when reading Chrome docs or questions here on SO, pay attention which manifest version it is in reference to.这种转变引入了如何构建清单(除其他外)的变化,因此在阅读 Chrome 文档或 SO 上的问题时,请注意它所参考的清单版本。

"manifest_version" : 2

Above entry means "use (the old) manifest version 2" but I strongly suspect you want the new version 3:以上条目的意思是“使用(旧)清单版本 2”,但我强烈怀疑您想要新版本 3:

"manifest_version" : 3

host_permission主机权限

(This key applies only to manifest version 3) It means you want to perform extension operations within the domain google.com and are requesting permission to do so. (此键仅适用于清单版本 3)这意味着您希望在域 google.com 内执行扩展操作并请求这样做的权限。 The array value "*://*.google.com" is called a match pattern , and the docs say "the path must be present in a host permission".数组值"*://*.google.com"称为匹配模式,文档说“路径必须存在于主机权限中”。

"host_permissions":[ "*://*.google.com" ]

so change it to include path:所以将其更改为包含路径:

"host_permissions":[ "*://*.google.com/*" ]

even though inchrome.cookies this is written differently (mistakes happen...!).即使在chrome.cookies 中这是不同的写法(错误发生......!)。 After making these changes the extension should load for debugging without errors.进行这些更改后,应加载扩展以进行调试而不会出错。

I have a few additional notes:我还有一些补充说明:

  1. "version" : "0.001" numbering is unusual, and you will see this changes to 0.1 after the extension loads. "version" : "0.001"编号是不寻常的,在加载扩展后,您会看到它更改为 0.1。 I suggest you change it to say 0.1 also in the manifest.我建议您在清单中也将其更改为 0.1。

  2. From the manifest seems your intent it to work with cookies and plan to do so in content script.从清单看来,您打算使用 cookie 并计划在内容脚本中这样做。 This is not going to work.这是行不通的。 Accessing the cookies API must be within the extension context in background or popup.访问 cookie API 必须在后台或弹出窗口的扩展上下文中。 Again, this is something to configure in the manifest, and I have added an example below.同样,这是要在清单中配置的内容,我在下面添加了一个示例。

Finally arriving to this:终于到了这个:

{
  "manifest_version" : 3,
  "name" : "coding train extension",
  "version" : "0.1",
  "host_permissions":[
    "*://*.google.com/*"
  ],
  "permissions":[
    "cookies"
  ],
  "background": {
    "service_worker": "background.js"
  }
}

Here is an example cookie extension by the Chrome team, which you may find useful.以下是 Chrome 团队的cookie 扩展示例,您可能会发现它很有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在我的manifest.json文件中包括jQuery扩展的jQuery - How to include jQuery in my manifest.json file for a chrome Extension 在Chrome扩展manifest.json中检测锚点 - Detect anchor in Chrome Extension manifest.json Chrome 扩展程序,如何在 manifest.json 中排除 chrome:// URI - Chrome extension, how to exclude chrome:// URIs in manifest.json 如何使用Chrome扩展Manifest.json修复内容脚本的UTF-8 Firebase错误? - How to fix UTF-8 Firebase Error for Content Script w/ Chrome Extension Manifest.json? Chrome扩展程序:Manifest.json在选项中包含JS - Chrome Extension: Manifest.json include JS in options 在Google Chrome扩展程序manifest.json中启用跨域权限 - Enable cross domain permission in google chrome extension manifest.json Chrome扩展程序-manifest.json加载文件夹中的所有js - Chrome Extension - manifest.json load all js in folder 如何访问 Firefox 扩展的 manifest.json 文件? - How to access the manifest.json file of a Firefox extension? Manifest.json中的Chrome扩展程序的自定义值? - Custom Values in Manifest.json for Chrome Extensions? 如何从Chrome扩展程序的选项页面启用/禁用manifest.json CSS内容脚本? - How to enable/disable manifest.json CSS content script from Chrome Extension's options page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM