Created
January 5, 2022 16:42
-
-
Save vmars316/e1411b319747918685dc9c203c0055ff to your computer and use it in GitHub Desktop.
Safe Browser
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<style> | |
body { | |
padding: 0; | |
margin: 0; | |
} | |
</style> | |
</head> | |
<body> | |
<header> | |
<div id="mainDiv" style="text-align: center;"> | |
<button id="back"><-</button> | |
<button id="forward">-></button> | |
<input id="url" type="url" value="https://google.com"/> | |
<button id="go">Go</button> | |
<button id="devtools">Toggle devtools</button> | |
</div> | |
</header> | |
</body> | |
<script> | |
// require('electron').ipcRenderer.on('Send-url', (__event, url) => { | |
// console.log("require('electron').ipcRenderer.on('Send-url" + url); | |
// document.getElementById("url").value = url; | |
// } | |
document.getElementById('back') | |
.addEventListener('click', () => browserview.back()) | |
document.getElementById('forward') | |
.addEventListener('click', () => browserview.forward()) | |
document.getElementById('go') | |
.addEventListener('click', () => browserview.loadURL(document.getElementById('url').value)) | |
document.getElementById('devtools') | |
.addEventListener('click', () => browserview.toggleDevtools()) | |
</script> | |
</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
const path = require('path') | |
const url = require('url') | |
const { app, BrowserWindow, BrowserView, ipcMain } = require('electron') | |
var holdUrl = "" ; | |
async function main() { | |
await app.whenReady() | |
const win = new BrowserWindow({ | |
width: 800, | |
height: 600, | |
webPreferences: { | |
preload: path.join(__dirname, 'preload.js') | |
} | |
}) | |
win.loadFile(path.join(__dirname, 'index.html')) | |
const view = new BrowserView() | |
view.setBounds({ | |
// y: 21, | |
y: 30, | |
x: 0, | |
width: win.getBounds().width, | |
// height: win.getBounds().height - 21 | |
height: win.getBounds().height - 30 | |
}) | |
view.setAutoResize({ | |
width: true, height: true | |
}) | |
win.setBrowserView(view) | |
// view.webContents.loadURL("https://duckduckgo.com") | |
view.webContents.loadURL("http://vmars.us/KidSafeBrowser/KidSafeBrowserHome.html") | |
view.webContents.on('will-navigate', (event, url) => { | |
console.log(" 1 main.js view.webContents.on( will-navigate = " + url) | |
// win.webContents.document.getElementById("url").value = holdUrl; | |
win.webContents.send('Send-url', url) ; | |
}) | |
view.webContents.on('did-start-navigation', (event, url) => { | |
holdUrl = url ; | |
console.log("2 main.js 'did-start-navigation' = " + holdUrl) | |
// win.webContents.send('update-address-bar-only', url) ; | |
}) // 'did-start-navigation' | |
ipcMain.on('browserview-load-url', (_, url) => { | |
console.log('Loading URL', url) | |
view.webContents.loadURL(url) | |
}) | |
ipcMain.on('browserview-back', () => { | |
console.log('Going back in history...') | |
view.webContents.goBack() | |
}) | |
ipcMain.on('browserview-forward', () => { | |
console.log('Going forward in history...') | |
view.webContents.goForward() | |
}) | |
ipcMain.on('browserview-toggle-devtools', () => { | |
console.log('Toggling devtools') | |
view.webContents.toggleDevTools() | |
}) | |
} | |
main() |
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
{ | |
"name": "bewildered-recommendation-harass-drrll", | |
"productName": "bewildered-recommendation-harass-drrll", | |
"description": "My Electron application description", | |
"keywords": [], | |
"main": "./main.js", | |
"version": "1.0.0", | |
"author": "vmars", | |
"scripts": { | |
"start": "electron ." | |
}, | |
"dependencies": {}, | |
"devDependencies": { | |
"electron": "16.0.5" | |
} | |
} |
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
const { ipcRenderer, contextBridge } = require('electron') | |
contextBridge.exposeInMainWorld('browserview', { | |
loadURL: (url) => ipcRenderer.send('browserview-load-url', url), | |
back: () => ipcRenderer.send('browserview-back'), | |
forward: () => ipcRenderer.send('browserview-forward'), | |
toggleDevtools: () => ipcRenderer.send('browserview-toggle-devtools'), | |
}) | |
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
const { ipcRenderer } = require('electron') | |
/* | |
var holdUrl = "" | |
pcRenderer.on('ping', (event, url) => { | |
console.log(url) | |
} | |
ipcRenderer.on(('Send-url', holdUrl) { | |
win.webContents.document.getElementById("url").value = holdUrl; | |
}); | |
*/ |
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
/* styles.css */ | |
/* Add styles here to customize the appearance of your app */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment