0

I am trying to run a script on active tab using option provided in chrome extension active tab. I am able to run using executeScript option

chrome.tabs.executeScript({
    code: "console.log('Hey there! from extn');"
  });

Calling console.log('Hey there! from extn'); and localStorage.setItem("myKey", "Set From Extn"); works fine.

But if i call some other script snippet ContextHub.getStore('profile').setItem('myKey', 'Value from extn');. It gives error Uncaught ReferenceError: ContextHub is not defined when extension code is running. If I run the same snippet from dev console for that tab, it works. So ContextHub variable is defined for that tab.

Do we need some extra configuration/permissions for this or there is any other API to be used for this? I need to be able to run script on active tab though extension, which I am able to run through dev console.

Sandeep Kumar
  • 1,758
  • 1
  • 22
  • 39
  • `ContextHub` is an object defined by a JS file (file loaded by Adobe AEM for personalization related libraries http://localhost:4508/etc/cloudsettings/default/contexthub.kernel.js) in Window namespace `window.ContextHub = window.ContextHub || {};`. – Sandeep Kumar Jul 20 '17 at 20:50
  • 3
    Ah, so it's in the web page context. You need to [Insert code into the page context using a content script](//stackoverflow.com/a/9517879) to read the variable and pass the results back to content script using CustomEvent as shown in the other answer. – wOxxOm Jul 20 '17 at 20:55

0 Answers0