Widget Architecture & Line-by-Line Code Guide
Learn how to embed, customize, and master Screenuoβs interactive screenshot and annotation engineβfrom beginner setup to advanced canvas memory optimization.
Step-by-Step: How to Embed & Use the Widget
Follow these four simple steps to add full-page capture and visual annotation to any website.
Add the HTML Container
Place an empty <div id="screenuo-widget" data-key="YOUR_KEY"></div> anywhere on your page and load embed.js asynchronously.
Automatic Domain Handshake
On load, the script validates your data-key and window.location.hostname via widget_config.php and applies your button color and permissions.
1-Click Cloud Capture
Clicking Capture calls executeCapture(), queues a background render job, and polls /URL/status/ with a live 0%β100% progress badge.
Annotate, Share & Restore
Tap the screenshot to launch the vector editor. Add text, numbered pins, shapes, or overlays, then save a shareable ?scn_edit=... link.
<div id="screenuo-widget" data-key="YOUR_WIDGET_KEY"></div> <script src="https://screenuo.com/embed.js" async></script>
Deep Dive: GPU Rendering, Memory Safety & JS API
Under-the-hood engineering techniques used in embed.js for 60 FPS mobile performance and external app integration.
Preventing 5K Mobile Crashes
Uncompressed 5K bitmaps consume ~60β100 MB RAM per canvas. getMaxWorkingSide() caps mobile working canvases at 1920px and releaseEditorMemory() frees buffers on save.
Dual-Canvas & Path Bitmap Cache
The clean base image lives in an offscreen baseOffscreen canvas (alpha: false). Freehand strokes are cached via getOrBuildPathCache() and batched with requestAnimationFrame.
Viewport Matrix Pinch-to-Zoom
Zoom uses edCtx.setTransform(viewZoom, 0, 0, viewZoom, viewPanX, viewPanY) instead of blurry CSS scaling, while clientToCanvasPoint() maps touch gestures into vector space.
Host JS API & Events
Control the widget programmatically via window.Screenuo.capture(url) or Screenuo.loadEdit(stateUrl), and listen to window.addEventListener('screenuo:captured', ...).
Complete Code Breakdown (embed.js)
Search any function, state variable, or canvas pipeline stage below.
#screenuo-widget element, extracts its data-key attribute, and creates a scoped localStorage key for version history.
1920px so 5K captures never trigger mobile out-of-memory browser crashes.
localStorage inside a try/catch guard so private browsing modes never throw storage exceptions.
image_url and state_url via both a DOM CustomEvent and postMessage for seamless CMS or e-commerce integration.
{ alpha: false }) lets the browser composite frames directly on the GPU, blitting baseOffscreen instead of slow CPU putImageData calls.
viewZoom and pan offsets.
requestAnimationFrame.
1. When multiple pins are present, the final destination pin switches to green (#539c57) with an inner white circle.
<textarea> with a 1px border and side/corner drag handles. Flexbox centering keeps text centered vertically and horizontally as the box expands.
.json file for shared re-editing.
Pointer Events with setPointerCapture and a 5px jitter deadzone so resistive touchscreens, styluses, and fingers work reliably without accidental drags.
project_json via XMLHttpRequest with live 0%β100% progress, and releases canvas buffers afterward.