"""Chromium-backed canvas interaction smoke without accessing a network endpoint.
Tests the shipped studio-canvas-bridge.js in a real sandboxed srcdoc iframe.
Server-authenticated editor E2E is separately covered by studio_canvas_smoke_v822.py.
"""
from pathlib import Path
from playwright.sync_api import sync_playwright
ROOT=Path(__file__).resolve().parents[1]
BRIDGE=(ROOT/'app/static/studio-canvas-bridge.js').read_text(encoding='utf-8')
DOC='''
'''
def run():
# `iframe.srcdoc` is used here just as in the production editor.
with sync_playwright() as playwright:
browser=playwright.chromium.launch(headless=True,executable_path='/usr/bin/chromium',args=['--no-sandbox'])
page=browser.new_page(viewport={'width':1280,'height':950})
page.set_content('')
page.evaluate('''content=>{window.events=[];window.addEventListener('message',e=>{if(e.source===document.querySelector('iframe').contentWindow)events.push(e.data)});document.querySelector('iframe').srcdoc=content;}''',DOC.replace('