Last active
July 24, 2021 06:07
-
-
Save andersevenrud/ef2194494b00f936f3ce8030084754b8 to your computer and use it in GitHub Desktop.
OS.js x-frame-bypass iframe example
This file contains hidden or 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
/* | |
This is just a demonstration of how this browser hack could be used | |
to make a "browser". | |
NOTE: This just bypasses *some* of the ways a browser allows loading | |
content within an iframe. Most google services etc does not work as | |
expected, and might just crash or not load. | |
*/ | |
import './index.scss'; | |
import osjs from 'osjs'; | |
import {h, app} from 'hyperapp'; | |
import {Box, BoxStyled, TextField, Toolbar, Button} from '@osjs/gui'; | |
import {name as applicationName} from './metadata.json'; | |
import 'x-frame-bypass'; | |
const homepage = 'https://www.bing.com'; | |
const render = ($content, win) => { | |
const view = (state, actions) => h(Box, {}, [ | |
h(Toolbar, { | |
}, [ | |
h(TextField, { | |
oninput: ev => actions.setTempUrl(ev.target.value), | |
onkeypress: ev => { | |
if (ev.keyCode === 13) { | |
actions.go(); | |
} | |
}, | |
value: state.temp, | |
box: {grow: 1} | |
}), | |
h(Button, { | |
onclick: () => actions.go() | |
}, 'Go') | |
]), | |
h(BoxStyled, { | |
grow: 1, | |
shrink: 1, | |
}, [ | |
h('div', { | |
key: state.key, | |
className: 'Window_WebBrowserWindow Window_WebBrowserWindow__inner', | |
oncreate: el => { | |
el.innerHTML = `<iframe src="${state.url}" is="x-frame-bypass"></iframe>`; | |
} | |
}) | |
]) | |
]); | |
return app({ | |
key: 0, | |
temp: homepage, | |
url: homepage, | |
}, { | |
setTempUrl: temp => ({temp}), | |
go: () => ({temp, key}) => { | |
win.emit('browser:go', temp); | |
return ({url: temp, key: key + 1}); | |
} | |
}, view, $content); | |
}; | |
const init = (proc) => { | |
const title = proc.metadata.title.en_EN; | |
const win = proc.createWindow({ | |
id: 'WebBrowserWindow', | |
title, | |
dimension: {width: 400, height: 400} | |
}) | |
.on('destroy', () => proc.destroy()) | |
.render(render); | |
win.on('browser:go', url => win.setTitle(`${title} - ${url}`)) | |
win.emit('browser:go', homepage); | |
}; | |
const register = (core, args, options, metadata) => { | |
const proc = core.make('osjs/application', {args, options, metadata}); | |
init(proc); | |
return proc; | |
}; | |
osjs.register(applicationName, register); |
This file contains hidden or 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
.Window_WebBrowserWindow { | |
&__inner { | |
width: 100%; | |
height: 100%; | |
} | |
iframe { | |
border: 0 none; | |
margin: 0; | |
padding: 0; | |
width: 100%; | |
height: 100%; | |
} | |
} |
And the contents of your index.js matches what is above ?
Its working. thanks for your time ❤️
Aha. Great! :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
1- added manually
2- npm install
3- npm run build