Skip to content

Commit

Permalink
app: add CORS headers for /api access for Browsertrix, fixes #232 (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikreymer authored Jul 8, 2024
1 parent 7c16857 commit 18cbbfb
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/electron/electron-recorder-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ class ElectronRecorderApp extends ElectronReplayApp
this.createRecordWindow(opts);
});

sesh.webRequest.onHeadersReceived((details, callback) => {
const { url, responseHeaders, method } = details;

// Allow access to Browsertrix APIs
if (url.indexOf("/api") >= 0) {
let { statusLine } = details;

if (method === "OPTIONS") {
statusLine = "HTTP/1.1 200 OK";
responseHeaders["Access-Control-Allow-Headers"] = "Authorization, Content-Type";
responseHeaders["Access-Control-Allow-Methods"] = "GET, PUT, POST";
}
responseHeaders["Access-Control-Allow-Origin"] = "*";
callback({responseHeaders, statusLine});
} else {
callback({responseHeaders});
}
});

sesh.on("will-download", (event, item, webContents) => {
const origFilename = item.getFilename();

Expand Down

0 comments on commit 18cbbfb

Please sign in to comment.