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== // ==UserScript==
// @name PNGExtraEmbed // @name PNGExtraEmbed
// @namespace https://coom.tech/ // @namespace https://coom.tech/
// @version 0.295 // @version 0.296
// @description uhh // @description uhh
// @author You // @author You
// @match https://boards.4channel.org/* // @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') { if (msg.data.msg.name == 'corsFetch') {
const { args } = msg.data.msg; const { args } = msg.data.msg;
const res = await ifetch(args[0], args[1]); try {
// don't report progress because monkeys don't have a way to expose partial responses anyway const res = await ifetch(args[0], args[1]);
const headersStr = (res as any).responseHeaders; // don't report progress because monkeys don't have a way to expose partial responses anyway
const headerObj = headerStringToObject(headersStr); const headersStr = (res as any).responseHeaders;
const headerObj = headerStringToObject(headersStr);
this.processor.postMessage({ this.processor.postMessage({
type: 'ipc', type: 'ipc',
id,
res: {
id, id,
ok: res.ok || true, res: {
setRes: true, id,
headers: headerObj, ok: res.ok || true,
responseHeaders: headersStr, setRes: true,
redirected: res.redirected, headers: headerObj,
type: res.type, responseHeaders: headersStr,
url: res.url, redirected: res.redirected,
status: res.status, type: res.type,
bodyUsed: res.bodyUsed, url: res.url,
statusText: res.statusText, 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]);
} }
}); // let's hope these are delivered in order :%)
if (!args[1].method || ['GET', 'POST'].includes(args[1].method)) {
const data = await res.arrayBuffer();
this.processor.postMessage({ this.processor.postMessage({
type: 'ipc', type: 'ipc',
id, id,
res: { res: {
id, id,
pushData: { pushData: {
data
} }
} }
}, [data]); }, []);
} } catch (e) {
// let's hope these are delivered in order :%) this.processor.postMessage({
this.processor.postMessage({ type: 'ipc',
type: 'ipc',
id,
res: {
id, id,
pushData: { res: {
id,
ok: false,
setRes: true,
headers: {},
responseHeaders: '',
redirected: false,
status: 400,
bodyUsed: false,
statusText: 'shit broke',
} }
} });
}, []); }
} }
// ignore other commands // ignore other commands
} }

Loading…
Cancel
Save