Skip to content

Commit

Permalink
Open URIs that get rejected by default security constraints.
Browse files Browse the repository at this point in the history
e.g. file:// and rvlinks://
  • Loading branch information
chadrik committed Jan 25, 2021
1 parent fe0d561 commit 1fe6a58
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/browser/components/MattermostView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ const preloadJS = `file://${remote.app.getAppPath()}/browser/webview/mattermost_
const ERR_NOT_IMPLEMENTED = -11;
const U2F_EXTENSION_URL = 'chrome-extension://kmendfapggjehodndflmmgagdbamhnfd/u2f-comms.html';

function extractURL(message) {
const matched = message.match(/Not allowed to load local resource:\s*(.+)/);
if (matched) {
return matched[1];
}
return '';
}

export default class MattermostView extends React.Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -190,6 +198,16 @@ export default class MattermostView extends React.Component {

webview.addEventListener('console-message', (e) => {
const message = `[${this.props.name}] ${e.message}`;

const retryUrl = extractURL(e.message);
console.log(`[${this.props.name}] url: ${retryUrl}`);
if (retryUrl) {
if (!shell.openExternal(decodeURI(retryUrl))) {
console.log(`[${this.props.name}] shell.openExternal failed: ${retryUrl}`);
}
return;
}

switch (e.level) {
case 0:
console.log(message);
Expand Down

0 comments on commit 1fe6a58

Please sign in to comment.