{"action":"created","issue":{"url":"https://api.github.com/repos/electron/electron/issues/1378","repository_url":"https://api.github.com/repos/electron/electron","labels_url":"https://api.github.com/repos/electron/electron/issues/1378/labels{/name}","comments_url":"https://api.github.com/repos/electron/electron/issues/1378/comments","events_url":"https://api.github.com/repos/electron/electron/issues/1378/events","html_url":"https://github.com/electron/electron/issues/1378","id":66940934,"node_id":"MDU6SXNzdWU2Njk0MDkzNA==","number":1378,"title":"webview navigation events","user":{"login":"felicienfrancois","id":988144,"node_id":"MDQ6VXNlcjk4ODE0NA==","avatar_url":"https://avatars2.githubusercontent.com/u/988144?v=4","gravatar_id":"","url":"https://api.github.com/users/felicienfrancois","html_url":"https://github.com/felicienfrancois","followers_url":"https://api.github.com/users/felicienfrancois/followers","following_url":"https://api.github.com/users/felicienfrancois/following{/other_user}","gists_url":"https://api.github.com/users/felicienfrancois/gists{/gist_id}","starred_url":"https://api.github.com/users/felicienfrancois/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/felicienfrancois/subscriptions","organizations_url":"https://api.github.com/users/felicienfrancois/orgs","repos_url":"https://api.github.com/users/felicienfrancois/repos","events_url":"https://api.github.com/users/felicienfrancois/events{/privacy}","received_events_url":"https://api.github.com/users/felicienfrancois/received_events","type":"User","site_admin":false},"labels":[{"id":144086588,"node_id":"MDU6TGFiZWwxNDQwODY1ODg=","url":"https://api.github.com/repos/electron/electron/labels/component/webview","name":"component/webview","color":"f9d0c4","default":false},{"id":35575880,"node_id":"MDU6TGFiZWwzNTU3NTg4MA==","url":"https://api.github.com/repos/electron/electron/labels/enhancement%20:sparkles:","name":"enhancement :sparkles:","color":"84b6eb","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":60,"created_at":"2015-04-07T17:14:51Z","updated_at":"2018-08-22T19:42:12Z","closed_at":"2017-02-09T21:50:06Z","author_association":"NONE","body":"It would be very useful to get events related to navigation:\n- `will-navigate`: when the webview is about to navigate (url have been changed but no requests have been emited yet). It could eventually be cancelled with `event.preventDefault()`)\n- `page-url-set`: like `page-title-set` but for url. It is different than `before-navigate` because it should also handle anchor changes and HTML5 url set without navigating (with `history.pushState` and `history.replaceState`)\n- `did-navigate`: after the navigation has occured (i.e. when a new entry have been pushed to history and canGoBack/canGoForward/canGo... may have changed)\n"},"comment":{"url":"https://api.github.com/repos/electron/electron/issues/comments/415155177","html_url":"https://github.com/electron/electron/issues/1378#issuecomment-415155177","issue_url":"https://api.github.com/repos/electron/electron/issues/1378","id":415155177,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNTE1NTE3Nw==","user":{"login":"nathanhleung","id":10874225,"node_id":"MDQ6VXNlcjEwODc0MjI1","avatar_url":"https://avatars2.githubusercontent.com/u/10874225?v=4","gravatar_id":"","url":"https://api.github.com/users/nathanhleung","html_url":"https://github.com/nathanhleung","followers_url":"https://api.github.com/users/nathanhleung/followers","following_url":"https://api.github.com/users/nathanhleung/following{/other_user}","gists_url":"https://api.github.com/users/nathanhleung/gists{/gist_id}","starred_url":"https://api.github.com/users/nathanhleung/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nathanhleung/subscriptions","organizations_url":"https://api.github.com/users/nathanhleung/orgs","repos_url":"https://api.github.com/users/nathanhleung/repos","events_url":"https://api.github.com/users/nathanhleung/events{/privacy}","received_events_url":"https://api.github.com/users/nathanhleung/received_events","type":"User","site_admin":false},"created_at":"2018-08-22T19:42:12Z","updated_at":"2018-08-22T19:42:12Z","author_association":"NONE","body":"Here was my solution:\r\n\r\n1. Hook into the `new_window` event and open all links that are set to open in a new window in an external browser:\r\n```js\r\n        webview.addEventListener('new-window', (e) => {\r\n            e.preventDefault();\r\n            const { protocol } = parse(e.url);\r\n            if (protocol.indexOf('http') === 0) {\r\n                shell.openExternal(e.url);\r\n            }\r\n        });\r\n```\r\n\r\n2. Make all links open in a new window:\r\n```js\r\n        webview.addEventListener(\"dom-ready\", function() {\r\n            webview.executeJavaScript(`\r\n                    const links = document.querySelectorAll(\"a[href]\");\r\n                    for (let i = 0; i < links.length; i += 1) {\r\n                      links[i].setAttribute(\"target\", \"_blank\");\r\n                    }\r\n          `);\r\n        });\r\n```"}}
{"actor":{"display_login":"nathanhleung"}}