0

I am planning to develop a google chrome extension which will help with a home brew functional testing framework. Here's the puzzle:

  • There is no predefined url pattern where test pages could reside.
  • I don't want the extension to get invoked by a match-all url pattern and then decide the page is of no interest.

What I want instead is for the extension to be completely dormant and to be able to invoke it from within the test pages.

Is this possible? If so,

  • What should I have in my manifest?
  • How do I implement the wake-up call in my test page javascript?
  • Could the call be made whilst I am developing the extension, before it gets an id?

Edit: This answer shows how a page could call an extension, but it needs an extension ID. Is there a way to get a temporary extension ID before the extension is published?

Community
  • 1
  • 1
Majid Fouladpour
  • 29,356
  • 21
  • 76
  • 127

1 Answers1

1

This is the first option I was thinking of but you do have to specify a second-level domain in the URL pattern.

  1. Add this to your manifest.json

    "externally_connectable": { "matches": ["://.example.com/*"] }

    As such: *://*.example.com/*

    not *://*.com

  2. More information about chrome extension message passing here: https://developer.chrome.com/extensions/messaging#external-webpage

  3. You will need to specify an id for the communication. You can get your extensions id by visiting chrome://extensions

Not knowing your stack or build process I would set up a separate dev and prod config file with my dev and prod id's in the respective files. This will help avoid pointing to your development extension when you release your app to production.

An alternate option would be to inject on each page and invoke your script depending on the pages content.

Gearoid
  • 173
  • 2
  • 7
  • Thanks, but this solution does not fit the first requirement: the url (including the domain) could not be specified in advance. Your tip on checking for the extension ID helped though. I was under the impression that unpacked extensions lacked an id altogether. That is not the case. – Majid Fouladpour May 04 '17 at 16:42