Home > Software engineering >  how i can fix error about chrome extension
how i can fix error about chrome extension

Time:10-19

I have written a simple extension just to learn how it works.

Manifest V3:

{  "name": "Sample",
   "version": "1.0",
   "manifest_version": 3,
   "action": {
      "default_name": "Sample",
      "default_popup": "popup.html"
    },
"background": {
    "service_worker": "background.js"
 },
"permissions": ["tabs", "storage", "activeTab", "clipboardRead", "scripting"],
"host_permissions": ["http://*/", "file://*/*", "https://*/", "*://*/*"]
}

popup.html:

.....
.....
<button id='getInfo' >GET</button>
.....
.....

popup.js:

....
document.getElementById("getInfo").addEventListener("click", function() {

chrome.tabs.query(
        {active: true, currentWindow: true},
        (tabs) => {
            chrome.scripting.executeScript({
                target: {tabId: tabs[0].id},
                file: ['func.js'],
            });
        });
 }

func.js:

alert("extension sample")

When i press the button 'GET' i receive an error in extension manager page. The error says: "Error handling response: TypeError: Error in invocation of scripting.executeScript(scripting.ScriptInjection injection, optional function callback): Error at parameter 'injection': Unexpected property: 'file'."

I have tried with function instead of the file and it works.

How i can fix this error? Thank you.

CodePudding user response:

chrome.scripting.executeScript does not have file property. You should use files property.

Search for "executeScript" in the official Google documentation below to see the sample.
https://developer.chrome.com/docs/extensions/reference/scripting/

  • Related