Skip to content

Instantly share code, notes, and snippets.

View dotproto's full-sized avatar

Simeon Vincent dotproto

View GitHub Profile
@dotproto
dotproto / _README.md
Last active July 2, 2026 18:02
Ugly, no good, very bad test extension exploring ways for an extension to back up files to the file system.

Recently I was looking for ways for WebExtensions to back up critical state. The contents of this gist are the very rough test extension I was using to explore options.

There are two main ways of interacting with this extension:

  1. The extensin's options page (options.html) has tests for working with <input type="file">, File System Access, and storing file handles in IndexedDB.
  2. The action context menu test ways to save files to disk using web APIs and the WebExtensions Downloads API.

Warning

File System Access tests may be destructive! Create a new temp directory to prevent accidetnally overwiting other files.

@dotproto
dotproto / _README.md
Last active January 29, 2026 05:09
Cross browser compatibility Info gathered while working on WebKit/WebKit#56662

Setup

  1. Copy the files in this gist into a temporary a local directory.
  2. CD into temporary directory and start a local HTTP server. I used npx http-server --proxy http://localhost:8080?, but anything should work
  3. In your borwser of choice, load the webext directory as a temporary extension.
    NOTE: You may need to grant additional host permissions after installation.
  4. If the extension didn't, open a new tab to http://localhost:8080
  5. Inspect the page, select the Network tab, and make the console visible.
  6. Reload the page.

When the page reloads, you should see a set of network requests that were blocked by the extension either in the Network tab directly or in the console.

@dotproto
dotproto / permission-cache.mjs
Created September 1, 2025 17:29
WebExtension permission cache
export class PermissionCache {
static areas = ["origins", "permissions", "data_collection"];
origins = [];
permissions = [];
data_collection = [];
ready;
constructor () {
this.ready = browser.permissions.getAll().then((grants) => {
@dotproto
dotproto / singleton.js
Last active January 4, 2026 23:57
An attempt at using ES6 classes to implement the Singleton design pattern.
class Singleton {
static #instances = new WeakMap();
/**
* @param {Boolean} useSharedThis Specifies whether or not `this` should be the singleton itself.
* If `true`, the Singleton class' constructor will return the singleton associated with the current
* prototype being instantiated. As a direct result, instance fields on the inherting class will be
* re-set on the singleton every time the descendant class is instantiated. This may created
* unnecessary and avoidable work. The main advantage of selecting `true` is that the sub-class does
* not have to explicitly return the singleton, since class constructors implicitly return `this`.
@dotproto
dotproto / clear-cookies.js
Created August 14, 2025 16:44
Clear all cookies URLs matching a regular expression in a given cookie store
(async () => {
const stores = await browser.cookies.getAllCookieStores();
const store = stores.at(1);
const exp = /(firefox|mozilla).(org|com|auth0.com)/;
const allCookies = await browser.cookies.getAll({storeId: s.id});
console.log("All cookies:", allCookies);
const filteredCookies = allCookies.filter(c => c.domain.match(exp));
const removeCookies = filteredCookies.map(cookie => {
@dotproto
dotproto / _README.md
Last active March 10, 2025 01:32
Host permission patterns with ports

This gist contains a WebExtension that tests how the browser that runs it handles ports host permission patterns.

Running tests

  1. (optional) Create a new browser profile to ensure that this test runs in a clean environment.
  2. Load this extension in your browser.
  3. Start a debug session for the extension's background context.
  4. (optional) Diable "debug" or "verbose" log messages
  5. Check if your browser auto-upgrades HTTP requests to HTTPS by calling testHttpUpgrades() in the console. If you see a console message that says "Your browser auto-upgraded one or more HTTP requests to HTTPS!", consult the HTTPs Upgrades section below.
@dotproto
dotproto / _README.md
Created November 14, 2024 02:14
timeout()

timeout() is a promise-based version of setTimeout() with AbortSignal support.

  1. Save the files from this gist in a local directory.
  2. Load that directory in Firefox as a temporary extension.
  3. Visit https://example.com and open developer tools.
  4. Click the "Open port" button and note the logged messages.
  5. Click the "Send message" button and note the logged messages.
  6. Wait ~30 seconds. Observe that a "Port disconnected!" message is logged.
  7. Wait another 30 seconds as described in the issue (#36097).
  8. Click "Open port" again.

Result: Could not reproduce the issue. The backgroudn starts up, recieves the connection request, and opens a port as expected.

@dotproto
dotproto / _README.md
Last active July 17, 2024 23:36
`onAuthRequired` event handler test cases

This gist contains a browser extension that tests browser support for testing how onAuthRequired event handlers handle different resoultion patterns. It created in support of reviewing https://github.com/mdn/webextensions-examples/pull/564.

Test # extraInfoSpec Description Chrome Firefox
1 blocking Synchronous object response
2 blocking Synchronous Promise response with async resolution
3 asyncBlocking Synchronous object response
4 asyncBlocking Synchronous Promise response with async resolution
5 asyncBlocking Async callback call with object
@dotproto
dotproto / background.js
Last active May 27, 2024 14:05
CORS Test (Chrome, Firefox) - This extension will begin performing HTTP requests against a bespoke test server immediately after installation. To view the results, open a devtools session for the extension's background context and look through the console output.
globalThis.browser ??= globalThis.chrome;
let testCounter = 0;
let corsTest = async (
{
client: {
forcePreflight = false,
mode = undefined,
},
server: {