0

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?

danbae
  • 563
  • 2
  • 8
  • 22
  • I don't think it would be possible; Not 100% sure but it seems very unlikely to be able to change the source code like that. Not sure if it would speed up your application but can you not do `"https://canvas.*/*"` as your matches? – James Nov 20 '19 at 10:28
  • @James: Chrome extensions can't have `matches` values like that. I did try it and got an error message, then found out here on SO that it was prohibited: https://stackoverflow.com/questions/40894136/chrome-extension-json-file-error-when-uploading – danbae Nov 20 '19 at 10:43
  • Ah right sorry, I guess using the include_globs doesn't speed it up as you still have to specify match everything? I've a feeling you might have to just live with the wait so or find a workaround. Does the delay on updates have that big an effect/are you updating really frequently? Maybe you could be fetching data from an API or something instead of uploading updates? – James Nov 20 '19 at 11:21
  • @James: I do use `include_globs` as well. When the dust has settled and the extension is more mature, this delay thing might not be such an issue as updates won't be needed as often. But I was also a bit annoyed with the lack of elegance in the present solution :) – danbae Nov 20 '19 at 11:25

1 Answers1

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

wOxxOm
  • 65,848
  • 11
  • 132
  • 136
  • OK.. let's see here. In alt 2, I am supposed to enter the code for programmatic injection in a `background.js` script. But this script is to respond to a message sent from... some script that requests the optional permissions, let's call that `request.js`. Since I now have removed the entire `content_scripts` section, how is this `request.js` script declared in the manifest such that it is recognised by the extension? – danbae Nov 25 '19 at 12:26
  • You'll show a button/command in your UI to grant the URL or API permission. – wOxxOm Nov 25 '19 at 12:43
  • Sorry, I'm thick. Where is my UI at? Are we talking about the options page? If not, how /where do I create the UI? – danbae Nov 25 '19 at 12:58
  • It can be an options page or a browser_action page or just a context menu on the icon, see the [overview](https://developer.chrome.com/extensions/overview#arch). – wOxxOm Nov 25 '19 at 13:01
  • I have tried to implement this solution but have run into some problems, detailed in a separate follow-up post, https://stackoverflow.com/questions/59039717/chrome-extension-programmatic-script-injection-error . – danbae Nov 25 '19 at 20:37