-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6374b31
Showing
10 changed files
with
10,656 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Webview Hangs | ||
|
||
Sample repo to test a problem with electron webview | ||
|
||
## Installation | ||
|
||
Clone and install dependencies with npm: | ||
|
||
```bash | ||
$ git clone https://github.com/Drawbotics/webview-hangs.git | ||
$ cd webview-hangs | ||
$ npm i | ||
``` | ||
|
||
## Run | ||
|
||
Run it with: | ||
|
||
```bash | ||
$ npm run dev | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const { app, BrowserWindow } = require('electron'); | ||
const url = require('url'); | ||
const path = require('path'); | ||
|
||
const interceptRequests = require('./intercept-requests'); | ||
|
||
|
||
const IS_DEV = process.env.NODE_ENV === 'development'; | ||
|
||
|
||
let mainWindow; | ||
|
||
function createWindow() { | ||
mainWindow = new BrowserWindow({ | ||
width: IS_DEV ? 1600 : 1100, | ||
height: 800, | ||
webPreferences: { | ||
webSecurity: false, | ||
}, | ||
}); | ||
|
||
mainWindow.loadFile(path.resolve(__dirname, '../render/index.html')); | ||
|
||
mainWindow.on('closed', () => { | ||
mainWindow = null; | ||
}); | ||
|
||
if (IS_DEV) { | ||
mainWindow.toggleDevTools(); | ||
} | ||
|
||
interceptRequests(); | ||
} | ||
|
||
|
||
app.on('ready', createWindow); | ||
|
||
|
||
app.on('window-all-closed', () => { | ||
if (process.platform !== 'darwin') { | ||
app.quit(); | ||
} | ||
}); | ||
|
||
|
||
app.on('activate', () => { | ||
if (mainWindow === null) { | ||
createWindow(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const { session } = require('electron'); | ||
const url = require('url'); | ||
const path = require('path'); | ||
|
||
|
||
module.exports = function interceptRequests() { | ||
session.defaultSession.webRequest.onBeforeRequest((details, next) => { | ||
const redirectURL = details.url === 'https://www.google.com/' | ||
? `file://${url.format(path.resolve(__dirname, '../render/redirected.html'))}` | ||
: null; | ||
if (redirectURL == null) { | ||
return next({ cancel: false }); | ||
} | ||
console.log('Redirecting to:', redirectURL); | ||
return next({ cancel: false, redirectURL }) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Webview Hangs</title> | ||
<style type="text/css"> | ||
html, body { | ||
height: 100%; | ||
font-size: 14px; | ||
} | ||
#root { | ||
min-height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
.webview { | ||
width: 100%; | ||
height: 100%; | ||
flex: 1; | ||
border: 1px solid black; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="root"> | ||
<button id="interact">Interact</button> | ||
<webview | ||
id="webview" | ||
class="webview" | ||
src="https://www.google.com" /> | ||
</div> | ||
<script type="text/javascript"> | ||
const path = require('path'); | ||
const url = require('url'); | ||
|
||
const localUrl = `file://${url.format(path.resolve(__dirname, 'redirected.html'))}`; | ||
const webview = document.getElementById('webview'); | ||
const interact = document.getElementById('interact'); | ||
|
||
webview.addEventListener('dom-ready', () => { | ||
if (webview.getURL() === localUrl) { | ||
return; | ||
} | ||
webview.openDevTools(); | ||
webview.loadURL(localUrl); | ||
console.log(webview.getURL()); | ||
}); | ||
|
||
interact.addEventListener('click', () => { | ||
console.log(webview.getURL()); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
</head> | ||
<body> | ||
<h1>Redirected</h1> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"watch": [ "app/main" ] | ||
} |
Oops, something went wrong.