Intercept click to links in the embedded documentation and redirect them to the default browser
Summary: Intercept click to links in the embedded documentation and redirect them to the default browser. Reviewed By: passy Differential Revision: D29426270 fbshipit-source-id: 1d3d9613ff827f80287883768452b93701e95d96
This commit is contained in:
committed by
Facebook GitHub Bot
parent
9fc85730ba
commit
142859f0ed
@@ -18,6 +18,7 @@ import {
|
|||||||
globalShortcut,
|
globalShortcut,
|
||||||
session,
|
session,
|
||||||
nativeTheme,
|
nativeTheme,
|
||||||
|
shell,
|
||||||
} from 'electron';
|
} from 'electron';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
@@ -232,6 +233,20 @@ app.on('ready', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.on('web-contents-created', (_event, contents) => {
|
||||||
|
if (contents.getType() === 'webview') {
|
||||||
|
contents.on('new-window', async (event, url) => {
|
||||||
|
// Disable creating of native Electron windows when requested from web views.
|
||||||
|
// This can happen e.g. when user clicks to a link with target="__blank" on a page loaded in a web view,
|
||||||
|
// or if some javascript code in a web view executes window.open.
|
||||||
|
// Instead of the default implementation, we redirect such URLs to the operating system which handles them automatically:
|
||||||
|
// using default browser for http/https links, using default mail client for "mailto" links etc.
|
||||||
|
event.preventDefault();
|
||||||
|
await shell.openExternal(url);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function configureSession() {
|
function configureSession() {
|
||||||
session.defaultSession.webRequest.onBeforeSendHeaders(
|
session.defaultSession.webRequest.onBeforeSendHeaders(
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user