Menu

Connect your application

wireflip is the SDK package for Chrome and Firefox. Install and import it directly:

pnpm add wireflip

Run this JavaScript in your app’s browser entry point. It adds a button and displays the result on the page.

import { intercept } from 'wireflip';

const button = document.createElement('button');
const status = document.createElement('output');
document.body.append(button, status);

async function connect() {
  button.disabled = true;
  button.textContent = 'Connecting…';
  try {
    const session = await intercept.connect();
    status.textContent = '';
    button.textContent = 'Enable CORS';
    button.onclick = async () => {
      button.disabled = true;
      try {
        await session.requestCors({ reason: 'Preview staging data' });
        status.textContent = 'CORS enabled for this site.';
      } catch (error) {
        status.textContent = error.type === 'user-cancel'
          ? 'Request cancelled.' : error.message;
      } finally {
        button.disabled = false;
      }
    };
  } catch (error) {
    status.textContent = error.type === 'not-installed'
      ? 'Install or enable Wireflip, reload this page, then retry.' : error.message;
    button.textContent = 'Retry connection';
    button.onclick = connect;
  } finally {
    button.disabled = false;
  }
}

void connect();

Website mutations require approval in a Wireflip-owned window by default, including enabling CORS and creating drafts. A site can disable its site-specific CORS setting from a click or keyboard action without a second confirmation. Start these requests from a real click or keyboard action. The real top-level page origin determines their scope.

Only the user can turn on Trust this site to control rules in the extension popup. Trust is stored for that exact origin (scheme, hostname and port), persists until revoked, and allows the site to manage its SDK-owned rules without repeated prompts. Credentialed CORS and explicit Authorization/Cookie request headers still require separate approval. Revoking trust restores prompts without changing existing rules.

A matching URL does not grant ownership. Rules created manually or by older extension versions remain managed inside Wireflip; sites cannot take them over. The retained legacy hosted bridge always asks before enabling CORS.

session.capabilities.interception reports whether the browser supports synthetic responses or body replacement, synthetic preflights or header-only repair, reasoned network failures or cancellation, and distinct or combined Fetch/XHR resource types. Applications should use these values instead of inferring behavior from the user agent.

Create a disabled rule draft

createDraftButton.addEventListener('click', async () => {
  try {
    await session.createRuleDraft({
      name: 'Simulate slow projects API',
      urlPattern: 'https://api.example.com/projects/*',
      methods: ['GET'],
      resourceTypes: ['XHR', 'Fetch'],
      actions: [{ type: 'delay', milliseconds: 800 }],
    });
  } catch (error) { console.error(error); } // Show feedback in your UI
});

createRuleDraft creates a disabled rule scoped to the calling origin after authorization. By default, the workspace opens so the user can review and enable the draft. It does not grant future permission to the site.

API reference

  • intercept.connect({ timeout? }) → InterceptSession
  • intercept.isAvailable() → boolean
  • intercept.openStorePage()
  • session.getStatus({ ruleId? })
  • session.requestCors({ credentials?, reason? })
  • session.disableCors()
  • session.createRuleDraft(rule, { openWorkspace? })
  • session.requestRule(rule, { id? }) — capability-check ruleActivation
  • session.enableRule(id) / session.disableRule(id) / session.deleteRule(id) — capability-check ruleManagement
  • session.openWorkspace()

The legacy isExtInstalled, isEnabled, enable, disable, openExtOptions, and openStorePage exports continue to call the new local bridge.

Handle unavailable extensions and cancellation

The example above handles both connection errors and cancelled approval. If Wireflip is unavailable, the rest of the application remains usable.

A connected SDK session means the website can communicate with the extension. Approved enabled rules run automatically on matching pages without starting request recording. Saved changes persist across refreshes and revisits and may affect other tabs from the same origin.

The requestRule and rule management APIs require extension 2.1 or later and SDK 2.1.0 or later. Check capabilities before using them. enableRule and disableRule return { id, enabled, ready, error? }; a paused group or browser execution error can leave an enabled rule unready. Show progress, cancellation and errors in your application. SDK calls do not create a website toast automatically.

// Connect before the click. An untrusted site needs a fresh gesture for each mutation.
const session = await intercept.connect();
disableButton.addEventListener('click', async () => {
  if (!session.capabilities.ruleManagement) return; // Offer to open Wireflip
  try {
    const result = await session.disableRule(savedRuleId);
    showMessage(result.error || 'Example disabled. Original requests are restored unless other rules apply.');
  } catch (error) {
    showMessage(error instanceof Error ? error.message : 'Unable to change the rule.');
  }
});

Existing integrations

The old cors-unlocker package and cors.forth.ink/message/ bridge remain supported. Migration is optional. Follow the migration guide when you are ready.

For interactive rule examples, visit Playground. For direct browser use without application code, start with the extension guide.

Upgrading website control to Wireflip 2.1

Wireflip 2.1 asks for approval in an extension window unless the user has manually trusted this exact site in Popup → Website control. Trust does not authorize sensitive credential access or transfer ownership of existing rules. Revoking trust restores prompts; saved rules remain in their current state.

With the updated extension, sites using wireflip@0.2.0 can keep calling requestCors() from a user click. Its confirmation expires after 50 seconds, within the SDK’s 60-second timeout. Draft creation that requires confirmation still needs SDK 2.1.0 because the old client waits only five seconds.

Users can approve enabling their site’s existing CORS setting in place, including settings saved manually or with an older extension. A click can turn it off directly. The rule keeps its identity, group and ownership. General rule editing and deletion still require website ownership.