First off I am not a programmer. I am self taught and don’t do it for a living. So I don’t know a lot about chrome extensions but I still managed to create one that we use at my workplace. This is a chrome extension and the site that it is used for is only validated to run on chrome so using a different browser in not an option.
I converted my extension to manifest V3 about a year ago but there were a couple things that I couldn’t figure out how to make work. The extension only runs on a few work computers so the parts I couldn’t get to work in V3 were kept in a small extension in V2 that runs on the computer in developer mode. The problem is that I believe that soon V2 will stop working so I am trying to find a solution to get it to work in V3.
if (document.querySelector("[id^=GridViewTissueTeamSignatures_][id$=_TextBoxESigPassword]")) {
// Select all elements with IDs starting with 'GridViewTissueTeamSignatures_' and ending with '_TextBoxESigPassword'
document.querySelectorAll("[id^=GridViewTissueTeamSignatures_][id$=_TextBoxESigPassword]").forEach(function(element) {
var num = element.id.split("_");
var span = document.createElement('span');
span.innerHTML = ' <button id="simbutton_' + num[1] + '" class="header-button blue" style="display:none;">Save</button>';
element.insertAdjacentElement('afterend', span);
});
// Add click event listeners to checkboxes
document.querySelectorAll("[id^=GridViewTissueTeamSignatures_][id$=_CheckBoxESigSign]").forEach(function(checkbox) {
checkbox.addEventListener('click', function(e) {
var num = this.id.split("_");
var simbutton = document.getElementById("simbutton_" + num[1]);
if (this.checked) {
simbutton.style.display = 'inline';
} else {
simbutton.style.display = 'none';
}
});
});
// Add click event listener for simbuttons
document.addEventListener('click', function(e) {
if (e.target.id && e.target.id.startsWith('simbutton')) {
e.preventDefault();
//document.querySelector("#GridViewTissueTeamSignatures_ctl02_SignatureBlockTissueTeamMember_ctl00_CheckBoxESigInvalidate").click();
document.querySelector("#FormLinkPanel_ButtonSave").click();
return false;
}
});
}
when it gets to the line
document.querySelector(“#FormLinkPanel_ButtonSave”).click();
I get the following in my console:
Refused to run the JavaScript URL because it violates the following Content Security Policy directive: “script-src ‘self’ ‘wasm-unsafe-eval’ ‘inline-speculation-rules’ http://localhost:* http://127.0.0.1:*”. Either the ‘unsafe-inline’ keyword, a hash (‘sha256-…’), or a nonce (‘nonce-…’) is required to enable inline execution. Note that hashes do not apply to event handlers, style attributes and javascript: navigations unless the ‘unsafe-hashes’ keyword is present
Here is the manifest. I wasn’t 100% sure of what I was doing so I’m not sure if every thing in it is necessary. I am changing the site name in the upload because it is a private site and not allowed to give out the address.
{
"name":"example.com Extension",
"description":"Helps with the **** part of example.com.",
"version":"3.0.8.6",
"manifest_version":3,
"icons":{
"48":"icon48.png",
"128":"icon128.png"
},
"permissions":[
"https://example.com/*"
],
"content_scripts":[
{
"run_at":"document_end",
"matches":[
"https://example.com/*"
],
"css":[
"css/style.css",
"css/jquery.multiselect.css"
],
"js":[
"js/dependencies/download.js",
"js/dependencies/pdf-lib.min.js",
"js/dependencies/jquery.min.js",
"js/dependencies/jquery-ui.min.js",
"js/dependencies/simulate.js",
"js/dependencies/JsBarcode.code128.min.js",
"js/dependencies/DYMO.Label.Framework.2.0.2.js",
"js/functions.js",
"js/content.js",
"js/main.js",
"js/QAfunction.js",
"js/addons/savebutton.js",
"js/addons/hospitalNames.js",
"js/addons/blood2.js",
"js/addons/pdf-lib/trif.js",
"js/addons/pdf-lib/versiti.js",
"js/addons/pdf-lib/lnh.js",
"js/addons/pdf-lib/VRL.js",
"js/addons/pdf-lib/BBAcult.js",
"js/addons/pdf-lib/Solvita.js",
"js/addons/pdf-lib/BodyBag.js",
"js/addons/pdf-lib/coroner.js",
"js/addons/pdf-lib/chain.js",
"js/addons/pdf-lib/property.js",
"js/addons/pdf-lib/shipping.js",
"js/addons/pdf-lib/VF.js",
"js/addons/pdf-lib/Ossium.js",
"js/addons/pdf-lib/OssiumCult.js"
]
}
],
"web_accessible_resources": [{
"resources": ["images/*.gif","images/*.png","labels/*.label","pdf/*.pdf","html/*.html"],
"matches": [
"https://example.com/*"
],
"extension_ids": []
}]
}
The line above it is a checkbox on the page and if I run that line instead it will click the checkbox. The code executes perfectly in V2.