Skip to content

Commit

Permalink
fix: responseType问题和gm_xhr url的相对位置处理
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Nov 22, 2021
1 parent 4d0e056 commit 288d751
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/apps/grant/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ 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 @@ -389,13 +390,11 @@ export class BackgroundGrant {
setTimeout(() => {
URL.revokeObjectURL(respond.response);
}, 60e3)
} else if (config.responseType == "json") {
} else {
try {
respond.response = JSON.parse(xhr.response);
respond.response = xhr.response;
} catch (e) {
}
} else {
respond.response = xhr.response;
}
try {
respond.responseText = xhr.responseText;
Expand Down Expand Up @@ -448,7 +447,7 @@ 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 || '';
let _this = this;

function deal(event: string) {
Expand Down
3 changes: 2 additions & 1 deletion src/apps/grant/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ export class FrontendGrant implements ScriptContext {

@FrontendGrant.GMFunction({ depend: ['CAT_fetchBlob'] })
public async GM_xmlhttpRequest(details: GM_Types.XHRDetails) {
let u = new URL(details.url, window.location.href);
let param: GM_Types.XHRDetails = {
method: details.method,
timeout: details.timeout,
url: details.url,
url: u.href,
headers: details.headers || {},
data: details.data,
cookie: details.cookie,
Expand Down

0 comments on commit 288d751

Please sign in to comment.