Inject findAndReplaceDOMText onto page via Chrome Extension?
Hi,
Is there a way of adding this to a chrome extension? I want to highlight all same words which involves me adding a span to those found.
I have tried to add it in the manifest.json like this;
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["lib/findAndReplaceDOMText.js", "content.js"]
}
],
as well as trying to append it via background.js (preload) or content.js (page) with something like this;
let script = document.createElement("script");
script.setAttribute("src", "lib/findAndReplaceDOMText.js");
(document.head || document.documentElement).appendChild(script);
script.remove();
However the console says;
findAndReplaceDOMText.js:7 Uncaught SyntaxError: Unexpected token <
I've successfully included it in my Chrome extensions. Do you get that same console error in the background page console AND in the normal console when you load it as a content script? What about using the same file locally?
It just sounds like there's something wrong with the file itself.
How did you set it up? Because this is suggested to add the file via a script tag in index.html.
I'll check when I get back, thx for the help so far
Same way you did it.
"content_scripts": [
{
"matches": ["file:///*.html*"],
"js": ["js/libs/findAndReplaceDOMText.js", "js/script.js"]
}
]
I'm using version 0.4.5 of the script, not minified.
Hmm weird. Yeah my error is saying
Uncaught ReferenceError: findAndReplaceDOMText is not defined
at HTMLDocument.getSelectionText (content.js:16)
getSelectionText @ content.js:16
I also downloaded the unminified version and put that in my lib folder.
My code is here if you wanna have a quick look - https://github.com/puyanwei/chrome-extension-same-highlighter
Thx so far for ur help, really appreciate it!