Reputation: 3386
I am working with chrome extension development.
Here I am call URL by xml http request:
var xhr = new XMLHttpRequest();
xhr.open("GET", "URL", true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var resp = JSON.parse(xhr.responseText);
alert(resp);
alert(xhr.responseText);
// innerText does not let the attacker inject HTML elements.
//document.getElementById("resp").innerText = xhr.responseText;
}
}
xhr.send();
When I posting same script popup window will open when send request But in case of chrome popup window not working.
When I hit same URL in browser then also a popup window open.
Please suggest me why this not working in case of chrome development.
Upvotes: 3
Views: 1647
Reputation: 2356
Javascript alert() is working in chrome extension popup but not perfect this time. The position of the alert window is not necessary in the middle of the screen but close to the top left corner. Sometimes it turns that the alert window doesn't (or hardly) appears, it is out from the visible screen. Annoying bug...my chrome always froze when I launched two alerts. The reason was the second alert window didn't appear, but when I hit the enter it run ahead.
console.log('test') --> keep mind you have to click on inspect popup (right click on the popup icon) instead inspect element (right click on the webpage).
Upvotes: 0
Reputation: 111255
Javascript alerts are not working in extension popups, you should avoid them. Use console.log
instead.
Upvotes: 3
Reputation: 895
put a check for xhr before xhr.open, if undefined then initialize it again. install some debugging tool like fiddler or firebug for chrome. and debug xhr in chrome. xmlhttprequest has problems sometimes with browsers
Upvotes: 0