让用户修改Chrome扩展程序的manifest.json内容的编程方法 [英] Programmatic method to let the user modify the manifest.json content of a Chrome extension

查看:464
本文介绍了让用户修改Chrome扩展程序的manifest.json内容的编程方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发与Canvas LMS一起使用的Chrome扩展程序.这样做的问题是Canvas订户具有不同的URL,这些URL没有公共的顶级域.例如,我大学的Canvas站点的URL为canvas.gu.se,而另一所学校的URL为canvas.myschool.edu.但是我不能在manifest.json文件中输入"matches":"https://canvas.*/*",因为不允许使用顶级通配符(请参阅,然后以编程方式(在content.js代码中)清除其中没有画布"的网站.

这可以以自己的方式行事,但Chrome Web Store对此并不满意,这使我的更新延迟了几天.

当然可以使用一个狭窄的/虚拟的matches值,然后要求用户自己编辑清单以包括在每种情况下使用的特定URL,但是他们这样做的可能性有多大?相反,我希望该扩展程序启动一个本地页面,该页面提示用户输入特定的URL,然后相应地在该特定计算机上编辑manifest.json文件.可能吗?如果可以,怎么办?

解决方案

网上商店中已安装的扩展程序无法修改,其内容受Chrome保护和验证.只有在开发人员模式下解压缩的本地扩展才可以修改.

解决方案:

  1. 除了您的<之外,还添加"include_globs": ["*://canvas.*/*"](信息). c9>.
    这很可能不会帮助您减少在网络商店中的审阅时间.

  2. 删除"content_scripts"部分,并将主机从"permissions"移至在chrome.tabs.onUpdated(信息)监听器中进行程序注入./p>

    这需要您切换到可选权限(您将显示一个按钮/命令在您的用户界面中授予URL权限),这将帮助您确定网络商店的审核时间.

    甚至还有更高级的 declarativeContent API(带有RequestContentScript操作,实际上稳定地支持该操作) Chrome).

I am developing a Chrome extension for use with the Canvas LMS. A problem with this is that Canvas subscribers have different URLs which do not have a common top level domain. For instance, my University's Canvas site has the URL canvas.gu.se while another school might have canvas.myschool.edu. But I can't enter "matches":"https://canvas.*/*" in the manifest.json file, since top-level wildcards are not allowed (see this post for elaboration). Instead, I have to enter "matches":"https://*/*", and then programmatically (in the content.js code) weed out sites that don't have "canvas" in them.

That works in its own kludgy way, but Chrome Web Store is not very happy about it, which delays my updates by days.

One could of course use a narrow/dummy matches value and then ask the users to edit the manifest themselves to include the specific URL in used in each respective case, but how likely would they be to do that? Instead I would like the extension to launch a local page that prompts the user to input the specific URL and then edits the manifest.json file on that particular machine accordingly. Would that be possible and if so, how?

解决方案

An installed extension from the web store cannot be modified, its contents is protected and verified by Chrome. Only unpacked local extensions in developer-mode can be modified.

Solutions:

  1. Add "include_globs": ["*://canvas.*/*"] (info) in addition to your "matches".
    This won't help you reduce the review time in the web store, most likely.

  2. Remove "content_scripts" section, as well as hosts from "permissions" and switch to programmatic injection in a chrome.tabs.onUpdated (info) listener.

    This requires you to switch to optional permissions (you'll show a button/command in your UI to grant the URL permission) which will help you with the web store review times.

    There's even a more advanced declarativeContent API (with RequestContentScript action which is actually supported in stable Chrome).

这篇关于让用户修改Chrome扩展程序的manifest.json内容的编程方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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