Skip to content

Instantly share code, notes, and snippets.

View beaufortfrancois's full-sized avatar
🏠
Working from home

François Beaufort beaufortfrancois

🏠
Working from home
View GitHub Profile
@beaufortfrancois
beaufortfrancois / background.js
Created January 17, 2024 15:18
WebGPU Chrome Extension
chrome.action.onClicked.addListener(async () => {
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice();
const canvas = new OffscreenCanvas(256, 256);
const context = canvas.getContext("webgpu");
const format = navigator.gpu.getPreferredCanvasFormat();
context.configure({ device, format });
const code = `
@beaufortfrancois
beaufortfrancois / headless-chrome-webgpu.ipynb
Last active February 14, 2024 06:17
Supercharge Web AI model testing: WebGPU, WebGL, and Headless Chrome
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
$ git diff --no-index chrome-webgpureport.txt safari-webgpureport.txt
diff --git a/chrome-webgpureport.txt b/safari-webgpureport.txt
index 67fffd7..3b6ed7c 100644
--- a/chrome-webgpureport.txt
+++ b/safari-webgpureport.txt
@@ -2,9 +2,9 @@ WebGPU Report
adapter info:
-------------
-architecture common-3
@beaufortfrancois
beaufortfrancois / audio-worklet-script-processor.md
Last active September 23, 2023 01:39
Web Audio: Migrate from ScriptProcessor to AudioWorklet

Web Audio: Migrate from ScriptProcessor to AudioWorklet

// script.js
button.onclick = async () => {
  const microphoneStream = await navigator.mediaDevices.getUserMedia({
    audio: true,
  });
@beaufortfrancois
beaufortfrancois / read-assigned-numbers.js
Created August 12, 2021 12:31
Parse Bluetooth Assigned Numbers (Service, Characteristics, Descriptors)
const fs = require("fs");
const LEGACY_UUIDS = {
"0x180F": "battery_service",
"0x2900": "gatt.characteristic_extended_properties",
"0x2901": "gatt.characteristic_user_description",
"0x2902": "gatt.client_characteristic_configuration",
"0x2903": "gatt.server_characteristic_configuration",
"0x2904": "gatt.characteristic_presentation_format",
"0x2905": "gatt.characteristic_aggregate_format",
@beaufortfrancois
beaufortfrancois / gist:583424dfef66be1ade86231fd1a260c7
Created September 3, 2020 09:21
Wheel mouse HID report descriptor
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
0x09, 0x02, // Usage (Mouse)
0xA1, 0x01, // Collection (Application)
0x09, 0x01, // Usage (Pointer)
0xA1, 0x00, // Collection (Physical)
0x05, 0x09, // Usage Page (Button)
0x19, 0x01, // Usage Minimum (0x01)
0x29, 0x03, // Usage Maximum (0x03)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
diff --git a/third_party/blink/renderer/modules/webgpu/gpu_buffer.cc b/third_party/blink/renderer/modules/webgpu/gpu_buffer.cc
index 9658796f2508..37a106c741f6 100644
--- a/third_party/blink/renderer/modules/webgpu/gpu_buffer.cc
+++ b/third_party/blink/renderer/modules/webgpu/gpu_buffer.cc
@ -127,6 +131,25 @@ void GPUBuffer::OnMapAsyncCallback(ScriptPromiseResolver* resolver,
WTF::ArrayBufferContents::SharingType::kNotShared);
mapped_buffer_ = DOMArrayBuffer::Create(contents);
+
+ auto* script_state = resolver->GetScriptState();
@beaufortfrancois
beaufortfrancois / mse-promisified.js
Last active April 9, 2018 11:47
MSE promisified
// In an ideal world, MSE would be that simple...
const mediaSource = new MediaSource()
video.srcObject = mediaSource
await mediaSource.ready
const sourceBuffer = mediaSource.addSourceBuffer('video/mp4')
const response = await fetch('https://example.com/init.mp4')
@beaufortfrancois
beaufortfrancois / finally.js
Created October 10, 2017 08:34
Promise.prototype.finally vs try/catch/finally with Async/Await
// Promise.prototype.finally
fetch('http://foo.bar')
.then(response => console.log(response))
.catch(error => console.log(error))
.finally(_ => console.log('finally'))
// try/catch/finally with Async/Await

Use cases

User enters PiP User resizes PiP window User exits PiP

Proposal #1