Wednesday, 7 August 2019

How can I detect in google chrome extension that I am logged in to another website?

I have a web application and I've made an additional google chrome extension for it. If I am logged in to the website, how to detect it in google chrome extension, so I do not have to log again in extension. When I am logged in to the site, I want the extension to detect that I am logged in to the site and logged in automatically to the extension.

I have error:

Could not load JavaScript file "content.js" for content script.

manifest.json

{
  "name": "EXTENSION",
  "options_page": "options.html",
  "background": {
    "page": "background.html"
  },

  "content_scripts": [{
    "matches": [ "*://*.app.com/*"  ],
    "js": [ "content.js" ],
    "all_frames": true
}],
  "browser_action": {
    "default_popup": "popup.html",
    "default_icon": "icon-34.png"
  },
  "icons": {
    "128": "icon-128.png"
  },
  "permissions": [
   "https://*/",
   "http://*/",
   "*://*.app.com/*",
    "storage"
  ],
  "version": "1.0",
  "manifest_version": 2,
  "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}

content.js

if(chrome && chrome.storage){
chrome.storage.sync.get('token', function(result){

    const item = result['access_token'];
    console.log(item);

    chrome.runtime.sendMessage(item, function(response) {
      console.log(response);
    });
});

}

var port = chrome.runtime.connect({name: 'test'});
port.onMessage.addListener(function(msg, port) {
    console.log(msg);
});
port.postMessage('from-iframe');

popup.js

chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
  console.log('popup got', msg, 'from', sender);
  sendResponse('response');
});

var iframePort; another function

chrome.runtime.onConnect.addListener(function(port) {
    iframePort = port;
    port.onMessage.addListener(function(msg, port) {
        console.log(msg);
    });
    port.postMessage('from-popup');
});

render(
  <App/>,
  window.document.getElementById("app-container")
);

popup.html

  <div id="app-container">
    <iframe width="500" height="500" src="https://app.com"></iframe>
  </div>



from How can I detect in google chrome extension that I am logged in to another website?

No comments:

Post a Comment