nothing-qrcpp
v1.0.0
Published
nothing-browser plugin — typed event wrapper and control API for the C++ PiggyQRDetector built into the Nothing Browser binary
Maintainers
Readme
nothing-qrcpp
Typed event callbacks and manual control API for the C++ QR detector built into the Nothing Browser binary (PiggyQRDetector).
The detector runs automatically — you do not need this package to receive QR events. It exists for discoverability, typed callbacks, and the site.qr control API.
Install
npm install nothing-qrcppUsage
const piggy = require('nothing-browser').default;
const qrcpp = require('nothing-qrcpp');
const fs = require('fs');
await piggy.launch({ mode: 'tab', binary: 'headless' });
await piggy.register('whatsapp', 'https://web.whatsapp.com', { single: true });
await piggy.extend(
qrcpp({
onQR: (d) => console.log(`Scan this QR (attempt ${d.attempts}):`, d.qrData),
onScanned: () => console.log('Authenticated!'),
onTimeout: () => console.log('QR rotated — new one incoming...'),
})
);
await piggy.whatsapp.navigate();Without this package
If you don't want the dependency, you can listen directly — the C++ emits these events regardless:
piggy.whatsapp.on('qr', (d) => console.log('Scan:', d.qrData));
piggy.whatsapp.on('qr:scanned', () => console.log('Done!'));
piggy.whatsapp.on('qr:timeout', () => console.log('Rotated'));Options
| Option | Type | When called |
|---|---|---|
| onQR | function | New or rotated QR is ready. data.qrData is "data:image/png;base64,..." |
| onScanned | function | QR scanned, WAWeb authenticated |
| onTimeout | function | QR expired and rotated (~every 20s) |
Events
| Event | Data | When |
|---|---|---|
| qr | { tabId, qrData, attempts } | New QR ready — qrData is a base64 PNG data URL |
| qr:scanned | { tabId } | Canvas disappeared — auth succeeded |
| qr:timeout | { tabId } | QR rotated before being scanned |
API (site.qr)
// Check current QR state
const state = await piggy.whatsapp.qr.status();
// { waiting: true, attempts: 2 }
// Force an immediate canvas check (skips the 500ms poll interval)
await piggy.whatsapp.qr.force();How the C++ detector works
- Polls the page every 500ms for a
<canvas>matching known WAWeb QR selectors - Extracts the canvas as a base64 PNG via
canvas.toDataURL() - Hashes the image to detect rotation — only emits
qrwhen the image actually changes - Prints the QR to the terminal automatically using iTerm2/Kitty inline image protocol with a plain data URL fallback
- When the canvas disappears, emits
qr:scannedand stops polling
Notes
- To force a fresh QR scan: call
site.storage.clear()before navigating (requiresnothing-innerstorage) - This plugin was made upon request — report any issues found
- This plugin is tailored specifically for WhatsApp sessions. You can use it on other sites but there is no guarantee it will work, and that is not a bug. A general-purpose
nothing-storageplugin will be released in the future to solve that qrDatais adata:image/png;base64,...URL — render it in a browser, pass it to a QR library, or display it in the terminal. The C++ already prints it automatically- The QR is canvas-based in WAWeb — there is no
<img>tag. Do not try to read it withfind.css()orprovide.text()
