{"id":699,"date":"2020-09-03T14:17:19","date_gmt":"2020-09-03T21:17:19","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/surface-duo\/?p=699"},"modified":"2020-09-24T10:20:45","modified_gmt":"2020-09-24T17:20:45","slug":"build-and-test-dual-screen-web-apps","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/surface-duo\/build-and-test-dual-screen-web-apps\/","title":{"rendered":"Build and test dual-screen web apps"},"content":{"rendered":"<p>\n  Hello dual-screen web developers!\n<\/p>\n<p>\n  In a <a href=\"https:\/\/devblogs.microsoft.com\/surface-duo\/dual-screen-web-experiences-preview\/?WT.mc_id=blog-surfaceduoblog-conceptdev\">previous blog post<\/a>, we talked about the dual-screen CSS <code>@media<\/code> primitives and the <code>getWindowSegments()<\/code> API, and how they could be tested with polyfill extensions. Now those features are built-in to Microsoft Edge and Chrome\u2122 browser canary builds, ready for developers to begin building dual-screen web apps.<\/p>\n<p>In this post, I\u2019ll briefly cover the new APIs and explain how to enable the dual-screen support so you can start building adaptive dual-screen web experiences today!\n<\/p>\n<h2>Dual-screen web APIs<\/h2>\n<p>\n  Here are some simple examples of the new dual-screen capabilities below:\n<\/p>\n<h3>CSS<\/h3>\n<p>You can use <code>@media (screen-spanning)<\/code> to apply styles only when the web browser is spanned:<\/p>\n<pre>@media (screen-spanning: single-fold-vertical) {\t\r\n   \/\/ styles applied in double-portrait (wide) mode\r\n}\r\n@media (screen-spanning: single-fold-horizontal) {\t\r\n   \/\/ styles applied in double-landscape (tall) mode\r\n}<\/pre>\n<p>New environment variables (<code>fold-top<\/code>, <code>fold-left<\/code>, <code>fold-width<\/code>, <code>fold-height<\/code>) are also available, to layout elements around the hinge:<\/p>\n<pre>@media (screen-spanning: single-fold-vertical) {\t\r\n    .blue {\r\n        width: 100px;\r\n        left: calc(env(fold-left) - 100px);\r\n        background-color: blue;\r\n    }\r\n}<\/pre>\n<h3>JavaScript<\/h3>\n<pre>const screenSegments = window.getWindowSegments();\r\nif( screenSegments.length > 1 ) {\r\n   \/\/ now we know the device is a foldable\r\n   \/\/ it's recommended to test whether screenSegments[0].width === screenSegments[1].width\r\n   \/\/ and we can update CSS classes in our layout as appropriate \r\n   document.body.classList.add('is-foldable');\r\n   \/\/ other changes as required for layout\r\n}<\/pre>\n<p>\n  Read the <a href=\"https:\/\/docs.microsoft.com\/dual-screen\/web\/?WT.mc_id=docs-surfaceduoblog-conceptdev\">dual-screen web developer documentation<\/a> for more details on how to use these new capabilities. The CSS and JavaScript enhancements are still in preview, so you&#8217;ll need to configure your browser (on the Surface Duo emulator, or on the desktop) to utilize them. To unlock these features to build and test your dual-screen ideas, follow the instructions below.\n<\/p>\n<h2>Test on the Microsoft Surface Duo emulator<\/h2>\n<p>\n  Today we released a new version of the Surface Duo emulator with support for dual-screen web development.<\/p>\n<p>To get started, download and install the new <a href=\"https:\/\/docs.microsoft.com\/dual-screen\/android\/get-duo-sdk?WT.mc_id=docs-surfaceduoblog-conceptdev\">Surface Duo emulator preview<\/a> (version 2020.806.1 or newer), then follow these steps to enable the dual-screen enhancements:\n<\/p>\n<ol>\n<li>\n  Open <strong>Microsoft<\/strong> <strong>Edge<\/strong> on the Surface Duo emulator\n<\/li>\n<li>\n  Type <strong>edge:\/\/flags<\/strong> in the address bar\n<\/li>\n<li>\n  Enable <strong>Experimental Web Platform features<\/strong> and restart the browser\n  <br \/>\n  <img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/emulator-flags.png\" alt=\"Surface Duo emulator flags configuration\" width=\"400\" height=\"349\" class=\"alignnone size-full wp-image-714\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/emulator-flags.png 400w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/emulator-flags-300x262.png 300w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><br\/>\n<em>Figure 1: Screenshot of Surface Duo emulator showing Experimental Web Platform features are enabled<\/em>\n<\/li>\n<li>\n  Once you enable the <strong>Experimental Web Platform<\/strong> features in the Surface Duo emulator, dual-screen CSS and JavaScript extensions will then be enabled, which you can test with <a href=\"https:\/\/conceptdev.github.io\/web-samples\/dual-screen-css\/boxes.html\">this example<\/a> on GitHub. On a single screen, the boxes appear next to each other, but when Microsoft Edge is spanned, CSS is used to render around the hinge:\n  <br \/>\n  <img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/emulator-web-css-1024x662.png\" alt=\"Surface Duo emulator with CSS web preview\" width=\"640\" height=\"414\" class=\"alignnone size-large wp-image-712\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/emulator-web-css-1024x662.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/emulator-web-css-300x194.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/emulator-web-css-768x496.png 768w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/emulator-web-css.png 1060w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><br\/>\n<em>Figure 2: Screenshot of Surface Duo emulator in dual-screen mode<\/em>\n<\/li>\n<li>\n  You can now view dual-screen enabled web content as it will appear on a Surface Duo.\n<\/li>\n<\/ol>\n<p>\n  Testing in the emulator will help you better understand how your web app interacts with the on-screen keyboard, for example, which is difficult to test usingthe desktop developer tools.\n<\/p>\n<h2>Build and test on the desktop<\/h2>\n<p>\n  In addition to viewing dual-screen layouts on the Surface Duo emulator, you can also build and test on the desktop with Microsoft Edge or Chrome canary versions.\n<\/p>\n<p>\n  The dual-screen emulation feature requires the Canary build of <strong>Microsoft<\/strong> <strong>Edge<\/strong> (v86.0.593.0 or newer), which you can <a href=\"https:\/\/www.microsoftedgeinsider.com\/download\">download from Microsoft Edge Insider<\/a> for Windows or macOS. Follow these steps to begin working with dual-screen websites:\n<\/p>\n<ol>\n<li>\n  Download, install, and open <strong>Microsoft<\/strong> <strong>Edge <\/strong>Canary build\n<\/li>\n<li>\n  Type <strong>edge:\/\/flags<\/strong> in the address bar (type <b>chrome:\/\/flags<\/b> in Chrome)\n<\/li>\n<li>\n  Enable <strong>Experimental Web Platform features<\/strong> (and restart the browser, if required)<strong><br \/><\/strong>\n  <img decoding=\"async\" width=\"1335\" height=\"715\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/word-image-2.png\" class=\"wp-image-702\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/word-image-2.png 1335w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/word-image-2-300x161.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/word-image-2-1024x548.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/word-image-2-768x411.png 768w\" sizes=\"(max-width: 1335px) 100vw, 1335px\" \/><br\/>\n<em>Figure 3: Screenshot of Microsoft Edge browser showing Experimental Web Platform features are enabled<\/em>\n<\/li>\n<li>\n  Navigate to a dual-screen-enhanced website like <a href=\"https:\/\/conceptdev.github.io\/web-samples\/dual-screen-css\/boxes.html\">this example<\/a> on GitHub\n<\/li>\n<li>\n  Choose the <strong>Settings and more<\/strong> menu (ellipsis\u2026) and then <strong>More tools &gt; Developer Tools<\/strong>\n<\/li>\n<li>\n  In the Developer Tools pane, choose the <strong>Settings<\/strong> (gear) button and then <strong>Experiments<\/strong> and check <strong>Emulation: Support dual screen mode<\/strong><br \/><img decoding=\"async\" width=\"684\" height=\"270\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/word-image-3.png\" class=\"wp-image-703\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/word-image-3.png 684w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/word-image-3-300x118.png 300w\" sizes=\"(max-width: 684px) 100vw, 684px\" \/><br\/>\n<em>Figure 4: Screenshot of Microsoft Edge browser showing Experiments settings<\/em>\n<\/li>\n<li>\n  You should be able to select <strong>Surface Duo<\/strong> as a target device, and use the \u201cdual-screen\u201d (book-like) icon to toggle between one and two screens.\n  <br \/>\n  <img decoding=\"async\" width=\"1389\" height=\"808\" src=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/word-image-4.png\" class=\"wp-image-704\" srcset=\"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/word-image-4.png 1389w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/word-image-4-300x175.png 300w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/word-image-4-1024x596.png 1024w, https:\/\/devblogs.microsoft.com\/surface-duo\/wp-content\/uploads\/sites\/53\/2020\/09\/word-image-4-768x447.png 768w\" sizes=\"(max-width: 1389px) 100vw, 1389px\" \/><br\/>\n<em>Figure 5: Screenshot of Microsoft Edge browser showing Surface Duo screen settings<\/em>\n<\/li>\n<li>\n  You can now use your regular web development workflow to build and test dual-screen web apps.\n<\/li>\n<\/ol>\n<p>\n  Now you\u2019re ready to start building and testing apps on the desktop and take advantage of using existing web development tools and debugging experiences.\n<\/p>\n<h2>Debug on the Surface Duo emulator from the desktop<\/h2>\n<p>\n  In addition to building and testing on the Microsoft Edge desktop, you can also connect to the Surface Duo emulator and debug websites from the emulator.\n<\/p>\n<p>\n  Follow these instructions below to <a href=\"https:\/\/docs.microsoft.com\/microsoft-edge\/devtools-guide-chromium\/remote-debugging\/surface-duo-emulator\/?WT.mc_id=docs-surfaceduoblog-conceptdev\">connect a Surface Duo emulator instance to Microsoft Edge desktop developer tools<\/a>. Remote debugging also <a href=\"https:\/\/docs.microsoft.com\/microsoft-edge\/devtools-guide-chromium\/remote-debugging\/?WT.mc_id=docs-surfaceduoblog-conceptdev\">works for Android devices<\/a>.\n<\/p>\n<h2>Examples to try<\/h2>\n<p>\n  Once you\u2019ve configured your Microsoft Edge desktop browser or Surface Duo emulator, try these dual-screen demos:\n<\/p>\n<ul>\n<li><a href=\"https:\/\/conceptdev.github.io\/web-samples\/dual-screen-css\/boxes.html\">Simple boxes<\/a> \n  <\/li>\n<li><a href=\"https:\/\/foldable-devices.github.io\/demos\/photo-gallery\/\">Photo gallery<\/a>\n  <\/li>\n<li><a href=\"https:\/\/foldable-devices.github.io\/demos\/battleship\/\">Battleship game<\/a>\n  <\/li>\n<\/ul>\n<h2>Resources and feedback<\/h2>\n<p>\n  I hope these examples help you to start building web-based dual-screen experiences. Visit the\u00a0<a href=\"https:\/\/docs.microsoft.com\/dual-screen\/web\/?WT.mc_id=docs-surfaceduoblog-conceptdev\" target=\"_blank\" rel=\"noopener noreferrer\">dual-screen web experiences documentation<\/a>\u00a0for more details.\n<\/p>\n<p>\n  We\u2019d love to hear from you! Please leave us feedback using our\u00a0<a href=\"http:\/\/aka.ms\/SurfaceDuoSDK-Feedback\" target=\"_blank\" rel=\"noopener noreferrer\">feedback forum<\/a>, or message me on\u00a0<a href=\"https:\/\/twitter.com\/conceptdev\" target=\"_blank\" rel=\"noopener noreferrer\">Twitter<\/a>\u00a0or\u00a0<a href=\"https:\/\/github.com\/conceptdev\" target=\"_blank\" rel=\"noopener noreferrer\">GitHub<\/a>.\n<\/p>\n<p><b>UPDATE:<\/b> Read more on the <a href=\"https:\/\/blogs.windows.com\/msedgedev\/2020\/09\/14\/introducing-dual-screen-foldable-web-apis\/?WT.mc_id=blog-surfaceduoblog-conceptdev\">Microsoft Edge blog<\/b>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello dual-screen web developers! In a previous blog post, we talked about the dual-screen CSS @media primitives and the getWindowSegments() API, and how they could be tested with polyfill extensions. Now those features are built-in to Microsoft Edge and Chrome\u2122 browser canary builds, ready for developers to begin building dual-screen web apps. In this post, [&hellip;]<\/p>\n","protected":false},"author":570,"featured_media":712,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[531,412,46,530],"class_list":["post-699","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-surface-duo-sdk","tag-css","tag-javascript","tag-surface-duo","tag-web"],"acf":[],"blog_post_summary":"<p>Hello dual-screen web developers! In a previous blog post, we talked about the dual-screen CSS @media primitives and the getWindowSegments() API, and how they could be tested with polyfill extensions. Now those features are built-in to Microsoft Edge and Chrome\u2122 browser canary builds, ready for developers to begin building dual-screen web apps. In this post, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts\/699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/users\/570"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/comments?post=699"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/posts\/699\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/media\/712"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/media?parent=699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/categories?post=699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/surface-duo\/wp-json\/wp\/v2\/tags?post=699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}