Programmatic method to let the user modify the manifest.json content of a Chrome extension

旧巷老猫 提交于 2020-01-22 02:34:16

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/58951909/programmatic-method-to-let-the-user-modify-the-manifest-json-content-of-a-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!