{"id":20857101,"url":"https://github.com/flipperdevices/webdfu","last_synced_at":"2025-05-12T07:32:37.008Z","repository":{"id":44647664,"uuid":"371120808","full_name":"flipperdevices/webdfu","owner":"flipperdevices","description":"Driver for working with DFU in a browser over WebUSB","archived":false,"fork":false,"pushed_at":"2022-02-02T12:53:17.000Z","size":608,"stargazers_count":36,"open_issues_count":3,"forks_count":9,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-10-16T12:20:12.819Z","etag":null,"topics":["dfu","dfuse","flipper"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flipperdevices.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-26T17:40:42.000Z","updated_at":"2024-06-18T00:50:22.000Z","dependencies_parsed_at":"2022-08-27T08:41:55.786Z","dependency_job_id":null,"html_url":"https://github.com/flipperdevices/webdfu","commit_stats":null,"previous_names":["flipper-zero/webdfu"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipperdevices%2Fwebdfu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipperdevices%2Fwebdfu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipperdevices%2Fwebdfu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flipperdevices%2Fwebdfu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flipperdevices","download_url":"https://codeload.github.com/flipperdevices/webdfu/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225129053,"owners_count":17425262,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dfu","dfuse","flipper"],"created_at":"2024-11-18T04:36:06.933Z","updated_at":"2024-11-18T04:36:07.598Z","avatar_url":"https://github.com/flipperdevices.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WebDFU\n\n[![NPM package](https://img.shields.io/npm/v/dfu)](https://www.npmjs.com/package/dfu)\n[![CI in main branch](https://github.com/Flipper-Zero/webdfu/actions/workflows/main.yml/badge.svg)](https://github.com/Flipper-Zero/webdfu/actions/workflows/main.yml)\n\nWebDFU — driver for working with DFU and DfuseDriver in a browser over [Web USB](https://wicg.github.io/webusb/) or [Web Bluetooth](https://webbluetoothcg.github.io/web-bluetooth/).\n\n- Reading and writing the current device firmware by [DFU 1.1](https://www.usb.org/sites/default/files/DFU_1.1.pdf)\n- [ST DfuSe](http://dfu-util.sourceforge.net/dfuse.html) download and upload firmware\n- Switching from the runtime configuration to the DFU bootloader (DFU detach)\n\n## Install\n\n```shell\nnpm i dfu\n```\n\n## Usage\n\nFull example in: [webdfu/demo](https://github.com/Flipper-Zero/webdfu/tree/main/demo)\n\nBasic example:\n\n```javascript\nimport { WebDFU } from \"dfu\";\n\nasync function connect() {\n  // Load the device by WebUSB\n  const selectedDevice = await navigator.usb.requestDevice({ filters: [] });\n\n  // Create and init the WebDFU instance\n  const webdfu = new WebDFU(selectedDevice, { forceInterfacesName: true });\n  await webdfu.init();\n\n  if (webdfu.interfaces.length == 0) {\n    throw new Error(\"The selected device does not have any USB DFU interfaces.\");\n  }\n\n  // Connect to first device interface\n  await webdfu.connect(0);\n\n  console.log({\n    Version: webdfu.properties.DFUVersion.toString(16),\n    CanUpload: webdfu.properties.CanUpload,\n    CanDownload: webdfu.properties.CanDownload,\n    TransferSize: webdfu.properties.TransferSize,\n    DetachTimeOut: webdfu.properties.DetachTimeOut,\n  });\n\n  // Read firmware from device\n  try {\n    const firmwareFile = await webdfu.read();\n\n    console.log(\"Read: \", firmwareFile);\n  } catch (error) {\n    console.error(error);\n  }\n\n  // Write firmware in device\n  try {\n    // Your firmware in binary mode\n    const firmwareFile = new ArrayBuffer(\"\");\n    await webdfu.write(1024, firmwareFile);\n\n    console.log(\"Written!\");\n  } catch (error) {\n    console.error(error);\n  }\n}\n\n/*\n  The browser's security policy requires that WebUSB be accessed only by an explicit user action.\n  Add the button in your html and run the WebDFu after click in button.\n  In HTML: \u003cbutton id=\"connect-button\"\u003eConnect\u003c/button\u003e\n*/\ndocument.getElementById(\"connect-button\").addEventListener(\"click\", connect);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflipperdevices%2Fwebdfu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflipperdevices%2Fwebdfu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflipperdevices%2Fwebdfu/lists"}