0

How to call the VueJs object via Chrome Extension?

I'm using the chrome.tabs.executeScript function to try to execute the code inside the active tab.

The idea is to change the values ​​of the fields.

So far I am unsuccessful.

Could anyone help?

My app Main

window.App = new Vue({
  store,
  render: h => h(App)
}).$mount("#app");

Chrome Extension

chrome.tabs.query({url:"http://localhost:8081/portaria/create"}, function(tabs) {

                        chrome.tabs.sendMessage(tabs[0].id, {content: true, body:response.documento}, function(response){

                            chrome.tabs.executeScript( tabs[0].id, {code:"console.log(App)"});
                            chrome.tabs.executeScript( tabs[0].id, {code:"console.log(window.App)"});
                            chrome.tabs.executeScript( tabs[0].id, {code:"window.App.$store.state.form.nfe.codigo = 102"});

                        });
                    });

enter image description here

**** UPDATE *****

Manifest

{
    "name": "Nfe - Nutrane",
    "version": "1.0",
    "manifest_version": 2,
    "content_scripts": [
        {
            "matches": ["<all_urls>"],
            "js": ["content.js"],
            "run_at": "document_start"
        }
    ],
    "browser_action": {
        "default_popup": "popup.html",
        "default_title": "Nfe"
    },
    "background":{
        "scripts": ["background.js"]
    },
    "permissions": ["tabs", "activeTab", "http://*/*", "https://*/*"],
    "web_accessible_resources": [
        "app.js"
      ]
}

Content

 var s = document.createElement('script');
  s.src = chrome.extension.getURL('app.js');
  (document.head||document.documentElement).appendChild(s);
  s.onload = function() {
      s.parentNode.removeChild(s);
  };
console.log(App)

enter image description here

marcelo.delta
  • 2,730
  • 5
  • 36
  • 71

0 Answers0