Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polyfill web serial on Android #514

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ <h2>How it works</h2>
Web Serial is available in Google Chrome and Microsoft Edge
browsers<span class="not-supported-i hidden">
(but not on your iOS device)</span
>. Android support should be possible but has not been implemented yet.
>. This includes Android.
</p>

<h3 id="improv">Configuring Wi-Fi</h3>
Expand Down
26 changes: 25 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^11.1.6",
"@types/w3c-web-serial": "^1.0.6",
"@types/w3c-web-usb": "^1.0.10",
"prettier": "^3.2.5",
"rollup": "^4.10.0",
"serve": "^14.2.1",
Expand All @@ -29,6 +30,7 @@
"improv-wifi-serial-sdk": "^2.5.0",
"lit": "^3.1.2",
"pako": "^2.1.0",
"tslib": "^2.6.2"
"tslib": "^2.6.2",
"web-serial-polyfill": "^1.0.15"
}
}
18 changes: 17 additions & 1 deletion src/install-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,20 @@ export class InstallButton extends HTMLElement {
}
}

customElements.define("esp-web-install-button", InstallButton);
function defineInstallButton() {
customElements.define("esp-web-install-button", InstallButton);
}

async function polyfillWebSerial() {
const { serial } = await import("web-serial-polyfill");
// @ts-ignore-next-line
navigator.serial = serial;
InstallButton.isSupported = true;
defineInstallButton();
}

if (!navigator.serial && navigator.usb) {
polyfillWebSerial();
} else {
defineInstallButton();
}