Skip to content

Commit

Permalink
fix: 兼容油猴的 responseType json处理
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Nov 22, 2021
1 parent e4d1625 commit 0d75d86
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/apps/grant/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ export class BackgroundGrant {
responseType: config.responseType,
};
if (xhr.readyState === 4) {
console.log(xhr);
if (config.responseType == "arraybuffer" || config.responseType == "blob") {
if (xhr.response instanceof ArrayBuffer) {
respond.response = URL.createObjectURL(new Blob([xhr.response]));
Expand All @@ -390,9 +389,9 @@ export class BackgroundGrant {
setTimeout(() => {
URL.revokeObjectURL(respond.response);
}, 60e3)
} else {
} else if (config.responseType == "json") {
try {
respond.response = xhr.response;
respond.response = JSON.parse(xhr.responseText);
} catch (e) {
}
}
Expand Down Expand Up @@ -447,7 +446,9 @@ export class BackgroundGrant {
let xhr = new XMLHttpRequest();
xhr.open(config.method || 'GET', config.url, true, config.user || '', config.password || '');
config.overrideMimeType && xhr.overrideMimeType(config.overrideMimeType);
xhr.responseType = config.responseType || '';
if (config.responseType != "json") {
xhr.responseType = config.responseType || '';
}
let _this = this;

function deal(event: string) {
Expand Down

0 comments on commit 0d75d86

Please sign in to comment.