Skip to content

Commit 0d75d86

Browse files
committed
fix: 兼容油猴的 responseType json处理
1 parent e4d1625 commit 0d75d86

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/apps/grant/background.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ export class BackgroundGrant {
380380
responseType: config.responseType,
381381
};
382382
if (xhr.readyState === 4) {
383-
console.log(xhr);
384383
if (config.responseType == "arraybuffer" || config.responseType == "blob") {
385384
if (xhr.response instanceof ArrayBuffer) {
386385
respond.response = URL.createObjectURL(new Blob([xhr.response]));
@@ -390,9 +389,9 @@ export class BackgroundGrant {
390389
setTimeout(() => {
391390
URL.revokeObjectURL(respond.response);
392391
}, 60e3)
393-
} else {
392+
} else if (config.responseType == "json") {
394393
try {
395-
respond.response = xhr.response;
394+
respond.response = JSON.parse(xhr.responseText);
396395
} catch (e) {
397396
}
398397
}
@@ -447,7 +446,9 @@ export class BackgroundGrant {
447446
let xhr = new XMLHttpRequest();
448447
xhr.open(config.method || 'GET', config.url, true, config.user || '', config.password || '');
449448
config.overrideMimeType && xhr.overrideMimeType(config.overrideMimeType);
450-
xhr.responseType = config.responseType || '';
449+
if (config.responseType != "json") {
450+
xhr.responseType = config.responseType || '';
451+
}
451452
let _this = this;
452453

453454
function deal(event: string) {

0 commit comments

Comments
 (0)