Comments (5)
@anarchylimes So, the plugin parses your manifest to find your content script.
// rollup.config.js
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import {
chromeExtension,
simpleReloader,
} from 'rollup-plugin-chrome-extension'
export default {
// Point this to your manifest
input: 'src/manifest.json',
output: {
dir: 'dist',
format: 'esm',
},
plugins: [
// always put chromeExtension() before other plugins
chromeExtension(),
simpleReloader(),
// the plugins below are optional
resolve(),
commonjs(),
],
}
// manifest.json
{
...
"content_scripts": [
{
"matches": [
"http://*/*",
"https://*/*"
],
// This path is relative to the manifest.json
"js": ["libs/content.js"]
}
],
...
}
from chrome-extension-tools.
I actually figured this out and it was because I was assuming it was cross browser compatible but firefox doesn't recognize how you're loading the content / background scripts. Even with the standard boilerplate it doesn't work. Maybe that's a stretch goal!
from chrome-extension-tools.
Whoops! My old GitHub enemy, Ctrl+Enter
, closed another issue on me. π
Answer is forthcoming...
from chrome-extension-tools.
The above issue is no longer an issue, however there is another issue that I'm only encountering with this plugin
No I understand how it connects various files to the manifest. What I'm talking about is that the content script is not being injected into the page. see this simple setup.
{
"manifest_version": 2,
"name": "NAME",
"version": "0.0.1",
"description": "NAME DESCRIPTION",
"permissions": ["activeTab", "tabs", "<all_urls>"],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": [
"js/content/content.js"
]
}
],
"background": {
"scripts": [
"js/background/background.js"
]
},
"browser_action": {
"default_icon": "img/logo.png",
"default_title": "NAME",
"default_popup": "html/popup.html"
}
}
then inside of js/content/content.js
document.body.style.border = '5px solid red'
yet literally nothing is happening on the page when there should be a simple border around everything.
in the dist/ folder the manifest looks like this
{
"manifest_version": 2,
"name": "NAME",
"version": "0.0.1",
"description": "DEVELOPMENT build with simple auto-reloader\n[2020-10-12 17:05:52] waiting for changes...",
"permissions": [
"activeTab",
"tabs",
"<all_urls>"
],
"content_scripts": [
{
"js": [
"assets/content-script-reloader-90067bfc.js",
"assets/content-b1554941.js"
],
"matches": [
"<all_urls>"
]
}
],
"background": {
"scripts": [
"assets/background-page-reloader-0ad65c2b.js",
"assets/background-21b4d0ae.js"
],
"persistent": true
},
"browser_action": {
"default_icon": "img/logo.png",
"default_title": "NAME",
"default_popup": "html/popup.html"
},
"web_accessible_resources": [
"js/content/content.js"
]
}
and the assets/content-b1154941.js looks like this
(function () {
'use strict';
const importPath = /*@__PURE__*/JSON.parse('"../js/content/content.js"');
import(importPath);
}());
and finally that content.js has
document.body.style.border = '5px solid red';
so why is it that the content script isn't being injected when all the paths look correct?
from chrome-extension-tools.
@anarchylimes I copy pasted your code over and it works for me... π€
Make sure to reload the page the first time after you load the extension. Chrome only injects a content script when the page is loading.
I'm going to close this issue since this is a separate problem, but if you want to open a new issue and link to a repo that reproduces this problem, I'd be happy to look at it!
This boilerplate might be a good place to start.
from chrome-extension-tools.
Related Issues (20)
- sidepanel.html not in dist folder HOT 1
- Assets loaded in content script result in 404 HOT 2
- Importing manifest.json in your app causes the CRXJS-generated manifest to be overwritten HOT 1
- match_origin_as_fallback field is missing in manifest schema HOT 1
- [crx:content-script-resources] Error: vite manifest is missing HOT 5
- Is there a method to simply copy without modifying the content_scripts?
- CSS in content_script is ignored. HOT 1
- crxjs does not support HTTPS flag in vite HOT 1
- Vite build for firefox
- inject.js error HOT 2
- Add React components interaction with content script example on the docs HOT 12
- Vite error in production build HOT 4
- Files imported with ?raw not updating after changes
- import of images in content_scripts are resulting in 404 HOT 3
- chrome.storage.local is undefined in content script
- `vite-plugin` breaks Vite dev server when `build.rollupOptions.input`s are present HOT 1
- Upgrade monorepo pnpm version to 8.x
- HRM and service script loader causes modules to be loaded twice with vite HOT 2
- Π‘anβt build a project with vite version newer than 5.0.11 HOT 10
- unable to run the dev script command HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chrome-extension-tools.