Revision fba67f09
Added by koszko over 1 year ago
content/haketilo_apis.js | ||
---|---|---|
43 | 43 |
*/ |
44 | 44 |
|
45 | 45 |
#FROM common/browser.js IMPORT browser |
46 |
#FROM common/misc.js IMPORT error_data_jsonifiable |
|
47 |
|
|
48 |
async function on_CORS_bypass(event) { |
|
49 |
const name = "haketilo_CORS_bypass"; |
|
50 |
|
|
51 |
console.warn("delme event", event.detail); |
|
52 |
|
|
53 |
if (typeof event.detail.id !== "string" || |
|
54 |
typeof event.detail.data !== "string") { |
|
55 |
console.error(`Haketilo: Invalid detail for ${name}:`, |
|
56 |
event.detail); |
|
57 |
return; |
|
58 |
} |
|
59 |
|
|
60 |
try { |
|
61 |
const data = JSON.parse(event.detail.data); |
|
62 |
var result = await browser.runtime.sendMessage(["CORS_bypass", data]); |
|
63 |
if (result === undefined) |
|
64 |
throw new Error("Couldn't communicate with Haketilo background script."); |
|
65 |
} catch(e) { |
|
66 |
var result = {error: error_data_jsonifiable(e)}; |
|
67 |
} |
|
68 |
|
|
69 |
const response_name = `${name}-${event.detail.id}`; |
|
70 |
const detail = JSON.stringify(result); |
|
71 |
window.dispatchEvent(new CustomEvent(response_name, {detail})); |
|
72 |
} |
|
46 | 73 |
|
47 | 74 |
function start() { |
75 |
window.addEventListener("haketilo_CORS_bypass", on_CORS_bypass); |
|
48 | 76 |
} |
49 | 77 |
#EXPORT start |
Also available in: Unified diff
allow injected scripts to bypass CORS using provided API