Browse Source

Make Userscript IPC properly report request errors to Worker

pull/46/head
coomdev 2 years ago
parent
commit
f63a538241
  1. 87
      dist/main.js
  2. 2
      main.meta.js
  3. 89
      main.user.js
  4. 83
      src/main.ts

87
dist/main.js

File diff suppressed because one or more lines are too long

2
main.meta.js

@ -1,7 +1,7 @@
// ==UserScript==
// @name PNGExtraEmbed
// @namespace https://coom.tech/
// @version 0.295
// @version 0.296
// @description uhh
// @author You
// @match https://boards.4channel.org/*

89
main.user.js

File diff suppressed because one or more lines are too long

83
src/main.ts

@ -265,51 +265,70 @@ class CommandProcessor {
}
if (msg.data.msg.name == 'corsFetch') {
const { args } = msg.data.msg;
const res = await ifetch(args[0], args[1]);
// don't report progress because monkeys don't have a way to expose partial responses anyway
const headersStr = (res as any).responseHeaders;
const headerObj = headerStringToObject(headersStr);
try {
const res = await ifetch(args[0], args[1]);
// don't report progress because monkeys don't have a way to expose partial responses anyway
const headersStr = (res as any).responseHeaders;
const headerObj = headerStringToObject(headersStr);
this.processor.postMessage({
type: 'ipc',
id,
res: {
this.processor.postMessage({
type: 'ipc',
id,
ok: res.ok || true,
setRes: true,
headers: headerObj,
responseHeaders: headersStr,
redirected: res.redirected,
type: res.type,
url: res.url,
status: res.status,
bodyUsed: res.bodyUsed,
statusText: res.statusText,
res: {
id,
ok: res.ok || true,
setRes: true,
headers: headerObj,
responseHeaders: headersStr,
redirected: res.redirected,
type: res.type,
url: res.url,
status: res.status,
bodyUsed: res.bodyUsed,
statusText: res.statusText,
}
});
if (!args[1].method || ['GET', 'POST'].includes(args[1].method)) {
const data = await res.arrayBuffer();
this.processor.postMessage({
type: 'ipc',
id,
res: {
id,
pushData: {
data
}
}
}, [data]);
}
});
if (!args[1].method || ['GET', 'POST'].includes(args[1].method)) {
const data = await res.arrayBuffer();
// let's hope these are delivered in order :%)
this.processor.postMessage({
type: 'ipc',
id,
res: {
id,
pushData: {
data
}
}
}, [data]);
}
// let's hope these are delivered in order :%)
this.processor.postMessage({
type: 'ipc',
id,
res: {
}, []);
} catch (e) {
this.processor.postMessage({
type: 'ipc',
id,
pushData: {
res: {
id,
ok: false,
setRes: true,
headers: {},
responseHeaders: '',
redirected: false,
status: 400,
bodyUsed: false,
statusText: 'shit broke',
}
}
}, []);
});
}
}
// ignore other commands
}

Loading…
Cancel
Save