content.js
console.log('content', window.location.href);
if (window.location.href.includes('sisu.php')) {
console.log('in sisu frame');
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
console.log('message', message);
if (message.action === 'DO_MY_THING') {
const { userInputP, userInputT } = message;
console.log(`DO_MY_THING with: ${userInputP} and ${userInputT}`);
}
return true;
});
}
sketch.js
const userinputP = document.getElementById("userinputP");
const userinputT = document.getElementById("userinputT");
const execute = document.getElementById("execute");
execute.addEventListener('click', async () => {
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
chrome.tabs.sendMessage(tab.id, {
action: 'DO_MY_THING',
userInputP: userinputP.value,
userInputT: userinputT.value
}, (response) => {
console.log('response', response);
});
});
manifest.json
{
"manifest_version": 3,
"name": "nsScript",
"version": "3.0",
"content_scripts": [
{
"matches": ["https://nutisport.eu/*"],
"js": ["content.js"],
"all_frames": true
}
],
"content_security_policy": {
"extension_pages": "script-src 'self'; object-src 'self';"
},
"permissions": ["tabs", "activeTab", "scripting"],
"action": {
"default_popup": "index.html",
"default_title": "nsScript"
}
}