feat(slides): add sandboxed Reveal.js viewer and editor preview
Build and publish container images / images (push) Successful in 9m2s
Release container images / release (push) Successful in 21s

This commit is contained in:
Anya Tokugawa committed 2026-11-08 22:10:52 +09:00
1 parent 09afb438c9
commit 02fb77f72b
30 files changed
+532 -9

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
(async()=>{
const assert=(ok,msg)=>{if(!ok)throw Error(msg)},delay=ms=>new Promise(r=>setTimeout(r,ms));
const wait=async fn=>{for(let n=0;n<300;n++){if(fn())return;await delay(25)}throw Error('Timeout '+fn)};
const ready=()=>document.querySelector('.slides-frame[data-ready=true]');
await wait(()=>window.PagesSlides);
const e=window.PagesEditor;
if(e){await wait(()=>document.querySelector('[data-editor-action=slides]')&&e.preview);e.paused=true;document.querySelector('[data-editor-action=slides]').click();}
await wait(ready);
const frame=ready(),source=e?.text(),historyLength=history.length;
assert(frame.dataset.count==='2','Wrong slide count');
assert(frame.sandbox.contains('allow-scripts')&&!frame.sandbox.contains('allow-same-origin'),'Isolation missing');
let isolated=false;try{isolated=!frame.contentDocument}catch{isolated=true}assert(isolated,'Frame can access parent origin');
assert(frame.getBoundingClientRect().height>=240,'Slide frame collapsed');
assert(frame.getBoundingClientRect().width<=innerWidth,'Mobile slide overflow');
if(e&&innerWidth<=700){assert(getComputedStyle(document.querySelector('.editor-pane')).display==='none','Mobile preview not full width');setEditorPreviewVisible(false);assert(getComputedStyle(document.querySelector('.editor-pane')).display!=='none','Mobile source inaccessible');setEditorPreviewVisible(true);}
const host=frame.parentElement;
// Verify the defensive DOM boundary independently of server sanitization.
PagesSlides.render(host,'<h1 onclick="alert(1)" data-background-iframe="https://evil.invalid">Safe</h1><script>alert(1)</scr'+'ipt><iframe src="https://evil.invalid"></iframe><img src="https://evil.invalid/x"><hr><p>Next</p>','/deck');
await wait(ready);
let projected=ready().srcdoc;
assert(!projected.includes('evil.invalid')&&!projected.includes('onclick=')&&!projected.includes('alert(1)'),'Unsafe content entered frame');
assert(!projected.includes('data-background-iframe'),'Reveal directives leaked');
assert(history.length===historyLength,'Slide render changed history');
let rejected=false;try{PagesSlides.render(host,'<p>x</p><hr>'.repeat(101),'/deck')}catch{rejected=true}assert(rejected,'Too many slides accepted');
if(e){
assert(e.text()===source,'Preview mutated canonical source');
e.setText('<h1>Edited</h1><hr><p>Second</p><hr><p>Third</p>');await e.renderPreview();await wait(ready);assert(ready().dataset.count==='3','Live preview stale');
document.querySelector('[data-editor-action=slides]').click();await wait(()=>!document.querySelector('.slides-frame'));assert(e.preview.textContent.includes('Edited'),'Normal preview not restored');
document.querySelector('[data-editor-action=slides]').click();await wait(ready);
clearTimeout(e.autosaveTimer);clearInterval(e.stateTimer);e.paused=true;
}else{PagesSlides.render(host,document.querySelector('[data-slides-source]').value,'/deck');await wait(ready);}
document.body.dataset.vimReady='true';
})().catch(error=>{const p=document.createElement('pre');p.id='error';p.textContent=error.stack;document.body.append(p)});
+12
View File
@@ -58,6 +58,18 @@ try {
const layout=await evaluate(`fetch('/_/api/v1/extension/organizer.tasks/dashboard').then(r=>r.json())`);if(layout.widgets[0].id!=='today'||layout.widgets.find(w=>w.id==='tasks').height!==4)throw Error('Pointer layout persistence failed');
await evaluate(`document.querySelector('#dashboard-controls button[aria-pressed]').click();scrollTo(0,0)`);
}
if (ready && process.env.PAGESWIKI_SLIDES_BROWSER === '1') {
const evaluate = async expression => (await call('Runtime.evaluate', {expression, returnByValue:true})).result.value;
const initialHistory = await evaluate('history.length');
await evaluate("document.querySelector('.slides-frame').focus()");
const key = async (key, code) => {await call('Input.dispatchKeyEvent',{type:'keyDown',key,code:key,windowsVirtualKeyCode:code});await call('Input.dispatchKeyEvent',{type:'keyUp',key,code:key,windowsVirtualKeyCode:code});};
await key('ArrowRight',39);
let advanced=false;for(let n=0;n<30;n++){if(await evaluate("document.querySelector('.slides-frame').parentElement.dataset.slideIndex") === '1'){advanced=true;break;}await delay(100);}
if(!advanced)throw Error('Slide keyboard navigation failed');
await key('ArrowLeft',37);await delay(150);
if(await evaluate("document.querySelector('.slides-frame').parentElement.dataset.slideIndex") !== '0')throw Error('Slide previous navigation failed');
if(await evaluate('history.length') !== initialHistory)throw Error('Slides polluted browser history');
}
if (screenshot) {
const {data} = await call('Page.captureScreenshot', {format: 'png'});
await writeFile(screenshot, Buffer.from(data, 'base64'));