2

I'm developing a Google Chrome Extension with InboxSDK that runs on Gmail. Now that the Gmail part is ready I want to expand to other websites with a subset of functionality that doesn't require InboxSDK nor Gmail features. My idea was to attempt to load InboxSDK (it checks for the supported origins) and if it doesn't load skip the Gmail features.

That being said I've run into a problem where an attempt to load InboxSDK's by calling InboxSDK.load(2, "app_id") prints a message in console: InboxSDK: Unsupported origin https://stackoverflow.com and stops executing any code beyond that point.

I don't need InboxSDK on origins other than Gmail.

Is it possible to run the same extension with InboxSDK on Gmail and without InboxSDK on other websites?

I'm providing a simple TypeScript code to illustrate this case:

import * as InboxSDK from "inboxsdk"

(async function main() {
    console.log("This will print on all websites")
    const sdk = await InboxSDK.load(2, "APP_ID")
    console.log("This will not be printed if the InboxSDK load fails")
})()

A possible solution I see is to implement the same origin check as InboxSDK does. I'm looking for a better solution that doesn't require duplicating this InboxSDK functionality.

Przemek
  • 31
  • 7

1 Answers1

0

How about you use different content scripts for initializing your code on gmail url and others. Then don't even load the inboxSDK where you don't need it. Should give you better control and only load inboxSDK when needed. This'll probably also resovle the issue with the "unsupported origin".

"content_scripts": [
{
  "matches": ["https://mail.google.com/*"],
  "js": [
    "libs/inboxsdk.js",
    "script/my_entry_with_inboxsdk.js"
  ],
  "runt_at": "document_end"
},
{
  "matches": ["https://*.everything-but-gmail.*"],
  "js": [
    "script/my_entry_without_inboxsdk.js"
  ],
  "runt_at": "document_end"

}

],