Skip to content

Commit 18cbbfb

Browse files
authored
app: add CORS headers for /api access for Browsertrix, fixes #232 (#240)
1 parent 7c16857 commit 18cbbfb

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/electron/electron-recorder-app.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@ class ElectronRecorderApp extends ElectronReplayApp
3939
this.createRecordWindow(opts);
4040
});
4141

42+
sesh.webRequest.onHeadersReceived((details, callback) => {
43+
const { url, responseHeaders, method } = details;
44+
45+
// Allow access to Browsertrix APIs
46+
if (url.indexOf("/api") >= 0) {
47+
let { statusLine } = details;
48+
49+
if (method === "OPTIONS") {
50+
statusLine = "HTTP/1.1 200 OK";
51+
responseHeaders["Access-Control-Allow-Headers"] = "Authorization, Content-Type";
52+
responseHeaders["Access-Control-Allow-Methods"] = "GET, PUT, POST";
53+
}
54+
responseHeaders["Access-Control-Allow-Origin"] = "*";
55+
callback({responseHeaders, statusLine});
56+
} else {
57+
callback({responseHeaders});
58+
}
59+
});
60+
4261
sesh.on("will-download", (event, item, webContents) => {
4362
const origFilename = item.getFilename();
4463

0 commit comments

Comments
 (0)