'Chrome extension doesn't work if I upload a local content script
I have a Google Chrome extension that I load from my computer. The extension folder contains 2 files, manifest.json and content.js like this:
{
"name": "My extension",
"version": "0.0",
"description": "My first extension",
"manifest_version": 2,
"content_scripts": [
{
"matches": [
"https://my_new_website.com/*"
],
"js": [
"./content.js"
],
"run_at": "document_idle",
"all_frames": true
}
]
}
and
const script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', 'https://my_website/content_file.js');
document.head.appendChild(script);
Now, I want to upload the content_file.js from my computer instead of https://my_website/. So, I replaced the following line:
script.setAttribute('src', 'https://my_website/content_file.js');
with
let image = require("path_to/content_file.js");
script.setAttribute('src', image);
But my Chrome extension didn't work the same as the first case. What am I doing wrong? Isn't the image command sending the same information as the online src file? Thank you.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
