3

I want to create a Chrome extension that replaces (overrides) existing function on a specific website.

I tried to define the manifest like this:

{
    "name": "My extension",
    "version": "1",
    "description": "desc",
    "manifest_version": 2,
    "content_scripts": [
        {
            "matches": ["http://www.mywebsite.com/*"],
            "js": ["jquery-1.3.2.js", "content.js"]
        }
    ]
}

And I put the new function in content.js, but it's not working. How can I fix it?

EDIT:

My content.js file contains a single Javascript function. it looks like this:

function fullLoad(ent)
{
    loadNow(ent);
}

I want that this function will override the real fullLoad function in the website. How can I do it?

Tal Levi
  • 321
  • 6
  • 19
  • Can you please share how it is not working? For instance, are no functions in content.js getting called? Are you expecting a function in content.js to override a function of the same name in another file? Thanks! – petewil-G Apr 26 '14 at 01:05
  • I edited my question, Can you have another look? Thanks. – Tal Levi Apr 26 '14 at 10:14
  • 1
    You need to inject your code into the page's context. See [this question](http://stackoverflow.com/questions/9515704/building-a-chrome-extension-inject-code-in-a-page-using-a-content-script). – Xan Apr 26 '14 at 10:16
  • @Xan I managed to inject the code, it's actually running. but the function `fullLoad` I defined is not override the original one. What's wrong? – Tal Levi Apr 26 '14 at 17:21
  • @TalLevi Do you understand the concept of different contexts? If you do inject the code (that requires non-standard approach!), and fullLoad is actually in the context of the page, it would throw an error. You need to override it with `fullLoad = function(ent){...};` and, again, make sure it's in the page's context and not your extension's sandboxed context. – Xan Apr 26 '14 at 17:29
  • @Xan Thanks for your help. Do you know sample extension I can look at? that overrides js function in a page? – Tal Levi Apr 26 '14 at 17:36
  • Can you update your code to show how you are injecting the content script? And could you explain why you need jquery? – Teepeemm Apr 27 '14 at 19:56

0 Answers0