Skip to content

Commit

Permalink
Parse XML from text, in content side.
Browse files Browse the repository at this point in the history
The already-parsed responseXML property cannot be message passed from background->content.  So take the responseText form and re-parse it, on the content side.

Fixes #2980
  • Loading branch information
arantius committed Jul 9, 2018
1 parent e5d59a6 commit 80b179b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/bg/api-provider-source.js
Expand Up @@ -231,6 +231,16 @@ function GM_xmlHttpRequest(d) {

let port = chrome.runtime.connect({name: 'UserScriptXhr'});
port.onMessage.addListener(function(msg) {
if (msg.responseState.responseXML) {
try {
msg.responseState.responseXML = (new DOMParser()).parseFromString(
msg.responseState.responseText,
'application/xml');
} catch (e) {
console.warn('GM_xhr could not parse XML:', e);
msg.responseState.responseXML = null;
}
}
let o = msg.src == 'up' ? d.upload : d;
let cb = o['on' + msg.type];
if (cb) cb(msg.responseState);
Expand Down
9 changes: 5 additions & 4 deletions src/bg/on-user-script-xhr.js
Expand Up @@ -55,18 +55,19 @@ function open(xhr, d, port, tabUrl) {
}

try {
responseState.responseXML = xhr.responseXML;
// Pass a flag to the content side, that the XML should be parsed.
responseState.responseXML = !!xhr.responseXML;
} catch (e) {
// Ignore failure. At least in responseType blob case, this access fails.
}

switch (event.type) {
case "progress":
case 'progress':
responseState.lengthComputable = event.lengthComputable;
responseState.loaded = event.loaded;
responseState.total = event.total;
break;
case "error":
case 'error':
console.log('error event?', event);
break;
default:
Expand All @@ -78,7 +79,7 @@ function open(xhr, d, port, tabUrl) {
}

port.postMessage(
{src: src, type: event.type, responseState: responseState});
{'src': src, 'type': event.type, 'responseState': responseState});
}

[
Expand Down
2 changes: 1 addition & 1 deletion src/user-script-obj.js
Expand Up @@ -10,7 +10,7 @@ reference any other objects from this file.
// Increment this number when updating `calculateEvalContent()`. If it
// is higher than it was when eval content was last calculated, it will
// be re-calculated.
const EVAL_CONTENT_VERSION = 12;
const EVAL_CONTENT_VERSION = 13;


// Private implementation.
Expand Down

0 comments on commit 80b179b

Please sign in to comment.