mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
tweak(phone/browser): include experimental iframe extension comp
This commit is contained in:
1 parent
a06ef07902
commit
929663af0c
4 files changed
+102
-1
No files matched your search
@@ -0,0 +1,96 @@
|
||||
customElements.define(
|
||||
'x-frame-bypass',
|
||||
class extends HTMLIFrameElement {
|
||||
static get observedAttributes() {
|
||||
return ['src'];
|
||||
}
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
attributeChangedCallback() {
|
||||
this.load(this.src);
|
||||
}
|
||||
connectedCallback() {
|
||||
this.sandbox =
|
||||
'' + this.sandbox ||
|
||||
'allow-forms allow-modals allow-pointer-lock allow-same-origin allow-scripts allow-top-navigation-by-user-activation'; // all except allow-top-navigation
|
||||
}
|
||||
load(url, options) {
|
||||
if (!url || !url.startsWith('http'))
|
||||
throw new Error(`Unable to load src ${url} does not start with http(s)://`);
|
||||
this.srcdoc = `<html>
|
||||
<head>
|
||||
<style>
|
||||
.loader {
|
||||
position: absolute;
|
||||
top: calc(50% - 25px);
|
||||
left: calc(50% - 25px);
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
background-color: #333;
|
||||
border-radius: 50%;
|
||||
animation: loader 1s infinite ease-in-out;
|
||||
}
|
||||
@keyframes loader {
|
||||
0% {
|
||||
transform: scale(0);
|
||||
}
|
||||
100% {
|
||||
transform: scale(1);
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="loader"></div>
|
||||
</body>
|
||||
</html>`;
|
||||
this.fetchProxy(url, options, 0)
|
||||
.then((res) => res.text())
|
||||
.then((data) => {
|
||||
if (data)
|
||||
this.srcdoc = data.replace(
|
||||
/<head([^>]*)>/i,
|
||||
`<head$1>
|
||||
<base href="${url}">
|
||||
<script>
|
||||
// X-Frame-Bypass navigation event handlers
|
||||
document.addEventListener('click', e => {
|
||||
if (frameElement && document.activeElement && document.activeElement.href) {
|
||||
e.preventDefault()
|
||||
frameElement.load(document.activeElement.href)
|
||||
}
|
||||
})
|
||||
document.addEventListener('submit', e => {
|
||||
if (frameElement && document.activeElement && document.activeElement.form && document.activeElement.form.action) {
|
||||
e.preventDefault()
|
||||
if (document.activeElement.form.method === 'post')
|
||||
frameElement.load(document.activeElement.form.action, {method: 'post', body: new FormData(document.activeElement.form)})
|
||||
else
|
||||
frameElement.load(document.activeElement.form.action + '?' + new URLSearchParams(new FormData(document.activeElement.form)))
|
||||
}
|
||||
})
|
||||
</script>`,
|
||||
);
|
||||
})
|
||||
.catch((e) => console.error('Unable to load proxy iframe service', e));
|
||||
}
|
||||
fetchProxy(url, options, i) {
|
||||
const proxies = (options || {}).proxies || [
|
||||
'https://cors-anywhere.herokuapp.com/',
|
||||
'https://api.codetabs.com/v1/proxy/?quest=',
|
||||
];
|
||||
return fetch(proxies[i] + url, options)
|
||||
.then((res) => {
|
||||
if (!res.ok) throw new Error(`${res.status} ${res.statusText}`);
|
||||
return res;
|
||||
})
|
||||
.catch((error) => {
|
||||
if (i === proxies.length - 1) throw error;
|
||||
return this.fetchProxy(url, options, i + 1);
|
||||
});
|
||||
}
|
||||
},
|
||||
{ extends: 'iframe' },
|
||||
);
|
||||
@@ -8,6 +8,8 @@
|
||||
/>
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<!-- Enable experimental proxy custom iframe webcomp -->
|
||||
<!-- <script type="module" src="./iframe.webcomp.js"></script>-->
|
||||
<title>Project Error - New Phone Who Dis</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -94,8 +94,10 @@ export const BrowserApp: React.FC = () => {
|
||||
/>
|
||||
<Box flexGrow={1}>
|
||||
<iframe
|
||||
is="x-frame-bypass"
|
||||
src={browserUrl}
|
||||
className={classes.iframe}
|
||||
// @ts-ignore
|
||||
class={classes.iframe}
|
||||
title="npwd-browser"
|
||||
ref={iframeRef}
|
||||
/>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export const promiseTimeout = (ms: number) => new Promise((res) => setTimeout(res, ms));
|
||||
Reference in new issue
Block a user