Injecting jQuery into Google.com using a Chrome Extension

Katie

I'm building a chrome extension and would quite like to inject jQuery into the Google website, but for some reason it just isn't working for me.

Here is my manifest file with the content_scripts:

"content_scripts": [{
    "matches": ["*://www.google.com/*"],
    "css": ["src/inject/inject.css"],
    "js": ["js/jquery/jquery.min.js", "src/inject/inject.js"],
    "run_at" : "document_start"
  }]

and jQuery is in the folder it is supposed to be. In my inject.js file I have:

$("body").append("Hello World");
console.log("Loaded.");

And strangely enough when I go to Google.com, Loaded. does appear in the console, but Hello World does not get appended to the body, nor do I get an error in the console which is very strange. I even did inside of inject.js:

if (window.jQuery) {  
    $("body").append("Hello World");
    console.log("Loaded.");
} else {
    console.log('Not Loaded.');
}

and Loaded. appeared in the console again, and Hello World did not get appened... I don't know what the problem is... It doesn't seem to make sense.

Any ideas? Thank you.

Anton Harald

content scripts run in sandboxed contexts. So you cannot change the page-dom from within them. But there is a workaround:

in your content-script, you add all your scripts via script-tags like this:

var script_tag = document.createElement("script");
script_tag.setAttribute("src", chrome.extension.getURL("js/jquery/jquery.min.js"));

document.head.appendChild(script_tag);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Chrome Extension injecting iframe

From Dev

Chrome extension not injecting css

From Dev

Using Google Charts in Chrome extension

From Dev

Using jquery in chrome extension popup

From Dev

Removing malware injecting into Google Chrome

From Dev

Why remove a script after injecting it, via a Google Chrome extension, into an pre-existing webpage?

From Dev

Chrome extension content script is not injecting in to most pages

From Dev

Injecting Javascript into Newly Created Tab in Chrome Extension

From Dev

Chrome extension injecting script get error

From Dev

Chrome extension content script is not injecting in to most pages

From Dev

Chrome extension injecting script get error

From Dev

jQuery click() not working in Google Chrome extension

From Dev

Unable to use jquery in google chrome extension

From Dev

google chrome extension manifest loading jquery

From Dev

Access Local Files using a Google Chrome Extension

From Dev

Redirect to url Using Google chrome Extension

From Dev

Defining a hotkey in Google documents using Chrome extension

From Dev

Injecting jQuery to webpage from Safari extension

From Dev

Authenticate Chrome extension with non-Google API using Google account

From Dev

Chrome extension popup injecting javascript more than once

From Dev

Chrome Extension: Injecting Javascript showing code rather than output

From Dev

Google Chrome Extension - simple jQuery to open a tags in browser

From Dev

Jquery auto popup with google chrome extension install check

From Dev

angularjs and google chrome extension

From Dev

angularjs and google chrome extension

From Dev

Error with google chrome extension

From Dev

Google Chrome extension malware?

From Dev

Changing the background of the google search page using my chrome extension

From Dev

Using google closure library inside chrome extension content script

Related Related

  1. 1

    Chrome Extension injecting iframe

  2. 2

    Chrome extension not injecting css

  3. 3

    Using Google Charts in Chrome extension

  4. 4

    Using jquery in chrome extension popup

  5. 5

    Removing malware injecting into Google Chrome

  6. 6

    Why remove a script after injecting it, via a Google Chrome extension, into an pre-existing webpage?

  7. 7

    Chrome extension content script is not injecting in to most pages

  8. 8

    Injecting Javascript into Newly Created Tab in Chrome Extension

  9. 9

    Chrome extension injecting script get error

  10. 10

    Chrome extension content script is not injecting in to most pages

  11. 11

    Chrome extension injecting script get error

  12. 12

    jQuery click() not working in Google Chrome extension

  13. 13

    Unable to use jquery in google chrome extension

  14. 14

    google chrome extension manifest loading jquery

  15. 15

    Access Local Files using a Google Chrome Extension

  16. 16

    Redirect to url Using Google chrome Extension

  17. 17

    Defining a hotkey in Google documents using Chrome extension

  18. 18

    Injecting jQuery to webpage from Safari extension

  19. 19

    Authenticate Chrome extension with non-Google API using Google account

  20. 20

    Chrome extension popup injecting javascript more than once

  21. 21

    Chrome Extension: Injecting Javascript showing code rather than output

  22. 22

    Google Chrome Extension - simple jQuery to open a tags in browser

  23. 23

    Jquery auto popup with google chrome extension install check

  24. 24

    angularjs and google chrome extension

  25. 25

    angularjs and google chrome extension

  26. 26

    Error with google chrome extension

  27. 27

    Google Chrome extension malware?

  28. 28

    Changing the background of the google search page using my chrome extension

  29. 29

    Using google closure library inside chrome extension content script

HotTag

Archive