2
votes

In main.js I am opening a tab and attaching a script with page-mod. The html file that is being opened it has a bunch of regular includes.

Sort of have two issues.

  1. The script from page mod does not get attached until after those other scripts are loaded, and also
  2. the regular scripts can't access variables defined in the script that is attached with page mod.
2

2 Answers

0
votes

You have to send messages.

Directly

In your page-mod, send a message:

page-mod.js

window.postMessage(projectUniqueId + '|' + message, domain);

If your page needs to work with all domains (being a plug-in), you might need '*' as a domain.

tab-attach.js

window.addEventListener('message',function(event){
  var words = event.data.split('|');
  if (words[0] == projectUniqueId){
    handle(words[1]);
  }          
});
0
votes

The script from page mod does not get attached until after those other scripts are loaded,

Specifying contentScriptWhen: 'ready' in the page-mod constructor should "[l]oad content scripts once DOM content has been loaded, corresponding to the DOMContentLoaded event"

the regular scripts can't access variables defined in the script that is attached with page mod.

Have a look at Expose objects to page scripts. You need to use

var contentScriptObject = {"greeting" : "hello from add-on"};

unsafeWindow.clonedContentScriptObject = cloneInto(contentScriptObject, unsafeWindow);

in the content script to make the object accessible.