explicitly parse a text response into JSON
This commit is contained in:
parent
561e7c585b
commit
9992ae3374
|
@ -364,12 +364,13 @@ document.documentElement.appendChild(document.createElement('script')).text = `(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const xhr = new XMLHttpRequest();
|
const xhr = new XMLHttpRequest();
|
||||||
xhr.responseType = 'json';
|
|
||||||
xhr.onloadend = xhr.onerror = () => {
|
xhr.onloadend = xhr.onerror = () => {
|
||||||
window.stop();
|
window.stop();
|
||||||
top.postMessage({
|
top.postMessage({
|
||||||
id: data.xhr.id,
|
id: data.xhr.id,
|
||||||
status: xhr.status,
|
status: xhr.status,
|
||||||
|
// [being overcautious] a string response is used instead of relying on responseType=json
|
||||||
|
// because it was invoked in a web page context so another extension may have incorrectly spoofed it
|
||||||
response: xhr.response,
|
response: xhr.response,
|
||||||
}, EXTENSION_ORIGIN);
|
}, EXTENSION_ORIGIN);
|
||||||
};
|
};
|
||||||
|
|
|
@ -832,8 +832,11 @@ window.addEventListener('showStyles:done', function _() {
|
||||||
chrome.webRequest.onBeforeRequest.removeListener(stripResources);
|
chrome.webRequest.onBeforeRequest.removeListener(stripResources);
|
||||||
searchFrameQueue.delete(data.id);
|
searchFrameQueue.delete(data.id);
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
if (data.response && data.status < 400) {
|
// [being overcautious] a string response is used instead of relying on responseType=json
|
||||||
resolve(data.response);
|
// because it was invoked in a web page context so another extension may have incorrectly spoofed it
|
||||||
|
const json = tryJSONparse(data.response);
|
||||||
|
if (json && data.status < 400) {
|
||||||
|
resolve(json);
|
||||||
} else {
|
} else {
|
||||||
reject(data.status);
|
reject(data.status);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user