2

I'm using HTML5 Sever Send Event to publish some status of the server. And I'm implementing a chrome extension to track the status, and notify user if needed.

But When I'm trying to create the EventSource object Chrome throws exception "Uncaught Error: SECURITY_ERR: DOM Exception 18"

var tracker = (function(url) {
    var source = new EventSource(url);
    var onMessage = function(e) {
        console.log(e);
    }

    source.addEventListener('new', onMessage);

    return {
        source: source,
        newMessage: onMessage
    };
})('http://localhost:3000/dispatching');

And I do added the url of the server into my extension permissions:

"permissions": [ 
    "http://localhost:3000/",
    "tabs"
]

But the permission doesn't really solve the problem! Any idea?

TimNew
  • 31
  • 1
  • 3
  • Which URL is your page hosted at? Is it a different port? – Steven de Salas Mar 20 '12 at 10:04
  • I'm not sure how they deal with ports but your [match pattern](http://code.google.com/chrome/extensions/match_patterns.html) should be `http://localhost:3000/*` in order to work. **However**, I don't believe that this permission is even required to call processes running locally on the machine (see [this question](http://stackoverflow.com/questions/9615089/how-adobe-shadow-chrome-extension-be-able-to-catch-dom-changes-without-any-relev)) so I think the problem may lie with your code. Unfortunately, I don't know much about this new API yet so can't really help there. – neocotic Mar 20 '12 at 10:44

1 Answers1

2

This looks like a Same Origin Policy issue occuring to HTML files loaded through the file:// protocol trying to contact the server via the http:// protocol.

Here is an article describing how to bypass SOP for your development environment.

When you go into production, my understanding is that that google chrome provides certain ways to by-pass the usual SOP restrictions normally imposed on browsers. This may be through the permissions JSON you mentioned however I'm not familiar enough with Chrome Extensions to say for certain.

Ah, hold on, this article might be useful.

Community
  • 1
  • 1
Steven de Salas
  • 18,983
  • 6
  • 63
  • 77