The interface inside the CSP
A device's interface comes from the firmware (the web/ folder, packed by devui pack) or from the product's publication (the same folder, published by devui publish). Either way, it is served by the cloud at an address of its own, https://<label>.thingface.com, and runs inside the portal's frame. The cloud does not trust it: the bundle is hostile input, and the page runs held by a content security policy (CSP) and a sandbox. This page says what fits inside them, so the interface works on the first try.
What the page can do
- Load its own files by relative path: scripts (
<script src=js/app.js>), modules, stylesheets, images, fonts, audio and video of the bundle. - Inline style (
style="..."and<style>): allowed. - Images and media from
data:andblob:(a chart drawn on the spot, a file the page made). - Talk to the board through the lib,
/_devui/v1.js(the only absolute path accepted):send,request,on, the state. The lib opens the channel at the page's own origin, the only network destination allowed. - Workers of its own bundle or from
blob:, and WebAssembly. - Open windows (
window.open, a link withtarget=_blank), download files and showalert/confirm. - Keep data in this browser through the lib (
dev.storage): the portal keeps it per user and per device, up to 64 KiB in the Free plan and 256 KiB in the paid ones. It goes at the logout, when someone else signs in on the browser, and after 90 days without use.
What the page cannot do
- An event attribute (
onclick=,onload=,href="javascript:..."): the CSP refuses it. Bind the events withaddEventListener. A<script>inline in the bundle's HTML may stay: the cloud computes the hash of each one when it gets the bundle and puts it in the CSP, so it has to be in the HTML that was uploaded, not built later by the page. - An absolute path (
/js/app.js,url(/font.woff2),href="/"): the cloud refuses the upload of a bundle that has one outside/_devui/. Use relative paths. - Network outside its own origin:
fetchto another site, a CDN, an external font, analytics. Everything the page uses goes inside the bundle. - Cookies,
localStorage,sessionStorage, IndexedDB and the Cache Storage: the page runs in an opaque origin (thesandboxwithoutallow-same-origin), and each of them throwsSecurityError. Usedev.storage. - A form that submits (
form-action 'none'): handle the submission in JavaScript and send it through the lib. - A frame inside the page (
frame-src 'none'),<object>and<embed>, and<base>. - Camera, microphone, location, USB, serial, Bluetooth, full screen and the clipboard: the
Permissions-Policyblocks them all. - Being framed by another site: only the market's portal may show the page.
Check before flashing or publishing
devui pack (and devui publish, which packs the same way) packs the folder and refuses what the cloud would refuse (an absolute path, an extension outside the list, the size). To see the page as the cloud serves it, open it through the portal: the browser's console shows each refusal of the CSP with its directive, and the LED example is a starting point that already fits all of this.
