-1

I am trying to load the same link of the tab into the popup window (this is not my primary purpose and i am doing this just to get acquainted) I am getting the error

Failed to load resource: net::ERR_FILE_NOT_FOUND

My js file is as follows

var pageGenerator = {
    requestPage: function() {
        var urlTosearch;
        chrome.windows.getCurrent(function(w) {
            chrome.tabs.getSelected(w.id,
            function (response){
                urlTosearch = response.url;
            });
        });
        var req = new XMLHttpRequest();
        req.open("GET", urlTosearch, true);
        req.onload = this.loadPage_.bind(this);
        req.send(null);
    },
    loadPage_: function (e) {
        var resp = e.target.responseText;
        document.body.insertAdjacentHTML( 'beforeend', resp);
    }
};
document.addEventListener('DOMContentLoaded', function () {
   pageGenerator.requestPage();
});

I have read that external pages can not be loaded onto the popup. Is it so? If true why? and if not how can it be done?

nnm
  • 1,335
  • 5
  • 18
  • 32
  • Use iframes - http://julip.co/2010/01/how-to-build-a-chrome-extension-part-3-loading-any-web-page-in-a-popup/ – levi Jun 02 '14 at 13:24
  • Still the same error Failed to load resource: net::ERR_FILE_NOT_FOUND chrome-extension://donolbgicbohlegccfjljabmnoadgmec/undefined – nnm Jun 02 '14 at 14:51
  • Try console.log the response.url to ensure that it is indeed defined – levi Jun 02 '14 at 14:56
  • `urlTosearch` will be undefined when you call `req.open`. See this question: [Why is my variable undefined after I modify it inside of a function? - Asynchronous code reference](http://stackoverflow.com/questions/23667086/why-is-my-variable-undefined-after-i-modify-it-inside-of-a-function-asynchron) – rsanchez Jun 02 '14 at 15:48
  • yes the url is defined yet somehow the page is not getting loaded.I got an xframe error which says Refused to display in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'. Then referring to http://stackoverflow.com/questions/15532791/getting-around-x-frame-options-deny-in-a-chrome-extension I followed the answer with 15 up votes yet the issue does not resolve. I am getting the error Uncaught TypeError: Cannot read property 'onHeadersReceived' of undefined . Please help – nnm Jun 02 '14 at 16:24
  • Are the files listed as [web_accessible_resources](https://developer.chrome.com/extensions/manifest/web_accessible_resources)? – abraham Jun 02 '14 at 17:03

2 Answers2

3

When receiving Failed to load resource: net::ERR_FILE_NOT_FOUND you probably didn't defined your url correctly. Since i don't see your url in your piece of code and i see no accepted answer i will share what i think goes wrong.

At first you have to define the url you are posting in your manifest with:

"permissions": [
  "http://www.yoururl.com/"
],

Also when calling your api by: yoururl.com/ the chrome extension will not call the api. Just simply because it thinks the url is withing the scope of your extension locally. To solve this you have to define http://www. or https://www. Now Chrome will recognize you try to load something from outside of the extension.

Dion Segijn
  • 2,625
  • 4
  • 24
  • 41
-1

Try using the Active Tab permission FROM A BACKGROUND script in order the get the URL of the current page. Then use chrome.tabs.create() to open a new tab with that same URL.

Details here: https://developer.chrome.com/extensions/activeTab

Flak DiNenno
  • 2,193
  • 4
  • 30
  • 57