Skip to content

Commit

Permalink
prevent navigation to external links
Browse files Browse the repository at this point in the history
  • Loading branch information
mbektas committed Feb 16, 2022
1 parent 559bd72 commit ea6e8b7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ app.on('ready', () => {
});

app.on("web-contents-created", (_event: any, webContents: WebContents) => {
// Prevent navigation to local links
// Prevent navigation to local links on the same page and external links
webContents.on('will-navigate', (event: Event, navigationUrl) => {
const jlabBaseUrl = `http://localhost:${appConfig.jlabPort}/`;
if (navigationUrl.startsWith(jlabBaseUrl) && navigationUrl.indexOf('#') !== -1) {
if (!(navigationUrl.startsWith(jlabBaseUrl) && navigationUrl.indexOf('#') === -1)) {
console.warn(`Navigation is not allowed; attempted navigation to: ${navigationUrl}`);
event.preventDefault();
}
Expand Down

0 comments on commit ea6e8b7

Please sign in to comment.