Skip to content

Commit

Permalink
add allow for iframe for camera, etc...
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Jul 5, 2024
1 parent cdca46e commit 625a2c1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions public/jsgist-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
const params = Object.fromEntries(new URLSearchParams(window.location.search).entries());
const url = new URL(params.url);

const allow = [
'accelerometer',
'bluetooth',
'camera',
'encrypted-media',
'display-capture',
'geolocation',
'gyroscope',
'microphone',
'midi',
'clipboard-read',
'clipboard-write',
'web-share',
'serial',
'xr-spatial-tracking',
].map(v => `${v} *`).join('; ');

let iframe;

async function startServiceWorker() {
Expand Down Expand Up @@ -144,6 +161,7 @@ iframe {
function insertInBlob(mainHTML, mainJS, mainCSS) {
applyCSSToSelfToRunContentInIFrame();
const iframe = document.createElement('iframe');
iframe.allow = allow;
const html = makePageHTML(mainHTML, mainJS, mainCSS);
registerSections(html);
const blob = new Blob([html], {type: 'text/html'});
Expand All @@ -155,6 +173,7 @@ iframe {
function insertInServiceWorker(mainHTML, mainJS, mainCSS) {
applyCSSToSelfToRunContentInIFrame();
const iframe = document.createElement('iframe');
iframe.allow = "accelerometer *; bluetooth *; camera *; encrypted-media *; display-capture *; geolocation *; gyroscope *; microphone *; midi *; clipboard-read *; clipboard-write *; web-share *; serial *; xr-spatial-tracking *"
const html = makePageHTML(mainHTML, mainJS, mainCSS);
registerSections(html);
cacheFile('/user-jsgist.html', 'text/html', html);
Expand Down
18 changes: 18 additions & 0 deletions src/components/Runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ import ServiceContext from '../ServiceContext.js';
import {createURL} from '../libs/url.js';
import * as winMsgMgr from '../libs/WindowMessageManager';

const allow = [
'accelerometer',
'bluetooth',
'camera',
'encrypted-media',
'display-capture',
'geolocation',
'gyroscope',
'microphone',
'midi',
'clipboard-read',
'clipboard-write',
'web-share',
'serial',
'xr-spatial-tracking',
].map(v => `${v} *`).join('; ');

export default class Runner extends React.Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -45,6 +62,7 @@ export default class Runner extends React.Component {
this.data = data;
this.removeIFrame();
const iframe = document.createElement('iframe');
iframe.allow = allow;
this.iframe = iframe;
iframe.src = isDevelopment
? createURL(`http://${window.location.hostname}:8081/runner-03.html`, {url: `http://${window.location.hostname}:8080/jsgist-runner.js`, ...extra})
Expand Down

0 comments on commit 625a2c1

Please sign in to comment.