Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject findAndReplaceDOMText onto page via Chrome Extension? #80

Open
puyanwei opened this issue May 27, 2019 · 4 comments
Open

Inject findAndReplaceDOMText onto page via Chrome Extension? #80

puyanwei opened this issue May 27, 2019 · 4 comments

Comments

@puyanwei
Copy link

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 <

@jkupczak
Copy link

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.

@puyanwei
Copy link
Author

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

@jkupczak
Copy link

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.

@puyanwei
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants