I want to make extention for browser that inject some javascript when page load in chrome
Assistant
Creating a Chrome extension that injects JavaScript into web pages when they load can be done using or by programmatically injecting scripts. Here’s a simple guide to build such an extension:
content scripts
Step 1: Create the Extension Files
You need at least these files:
manifest.json
content.js (your JavaScript to inject)
Step 2: Write manifest.json
This file tells Chrome about your extension and what permissions it needs.
For Manifest V3 (the newest version as of 2024):
json
{
"manifest_version": 3,
"name": "Inject JS on Page Load",
"version": "1.0",
"description": "Injects JavaScript into pages when they load",
"permissions": [
"scripting",
"activeTab"
],
"host_permissions": [
"<all_urls>"
],
"background": {
"service_worker": "background.js"
},
"action": {
"default_title": "Inject Script"
}
}
If you want automatic injection on page load of certain pages (without needing user interaction), you need a background script to listen to tab updates and inject the script.
Step 3: Create background.js
This script will inject your content script whenever a page loads.