## File: bridge/loader-features/loader/nma/README.md

# NMA — Noraneko Module Archive

This directory contains the **Noraneko Module Archive (NMA)** subsystem,
ported from [noraneko](https://github.com/f3liz-dev/noraneko). NMA is a
dynamic module loading system that uses [Sigstore](https://www.sigstore.dev/)
to verify the authenticity of module archives before loading them into the
browser.

Think of it as a secure, content-addressed module delivery pipeline: the
browser downloads a signed archive, verifies the signer's identity against a
trusted list, then swaps in updated modules at runtime — no full reinstall
required.

---

## Status: foundation only (types + state)

The Floorp port is **not yet complete**. Two of the five NMA files are
intentionally absent: they depend on `@freedomofpress/sigstore-browser`, which
is not yet a Floorp dependency.

### What's here

| File | Layer | What it does |
|------|-------|--------------|
| `types.ts` | N0 | All NMA interfaces and enums. No imports, no side effects — pure declarations. |
| `state.ts` | N1 | Singleton state container. Depends only on `types.ts`. Contains `TODO(Floorp)` comments marking what needs to change. |
| `mod.ts` | N3 (stub) | Public API re-export. Currently exports types and state only; fuller exports will be wired in once `core.ts` and `loader.ts` are ported. |

### What's missing

| File | Layer | Blocked by |
|------|-------|------------|
| `core.ts` | N2 | `@freedomofpress/sigstore-browser` — handles FS/network/crypto IO and Sigstore verification |
| `loader.ts` | N3 | `core.ts` — the orchestrator that drives init, verify, and hotswap |

---

## Architecture

NMA is a **self-contained subsystem**: it does not depend on the main loader's
`types/` or `state/` directories. The internal dependency graph is a clean
four-level DAG:

```
N0: types.ts       pure type definitions, no imports
       ↑
N1: state.ts       singleton state + event bus, imports types.ts only
       ↑
N2: core.ts        FS / network / crypto IO, Sigstore verify   ← needs sigstore-browser
       ↑
N3: loader.ts      orchestrator: initializeNMALoader, verifyNMA, hotswap…
    mod.ts         public re-export surface
```

The main loader connects to NMA at its own L2/L3
(`io/loading.ts` and `mod.ts`), using `initNMASystem()`, `isNMAActive()`,
`hasNMAModule()`, and `loadNMAModule()`. When NMA is inactive, `isNMAActive()`
returns `false` and the existing module path is taken unchanged — no
disruption to what works today.

---

## Next steps

Complete the port in this order:

- [ ] **Add `@freedomofpress/sigstore-browser` to Floorp's `deno.json` imports**

- [ ] **Port `nma/core.ts`** — FS/network/crypto IO and Sigstore verification  
  Reference: `bridge/loader-features/loader/nma/core.ts` in noraneko `rftr-bridge`

- [ ] **Port `nma/loader.ts`** — the orchestrator (`initializeNMALoader`,
  `verifyNMA`, `hotswapModule`, etc.)  
  Reference: `bridge/loader-features/loader/nma/loader.ts` in noraneko

- [ ] **Wire `initNMASystem()` into `bridge/loader-features/loader/index.ts`**  
  Call it early in the startup sequence, before `loadEnabledModules()`. NMA is
  self-silencing when no archive is present, so this won't break anything on
  its own.

- [ ] **Resolve the `TODO(Floorp)` markers in `state.ts`**:
  - Add Floorp's repository (e.g. `"nyanrus/Floorp"`) to
    `DEFAULT_NMA_TRUSTED_CONFIG.allowedRepositories`
  - Update `NMA_PATHS.FILE_PATTERN` to match Floorp's archive naming convention

- [ ] **Rename `PREF_HASH_STATE` in `core.ts`** from `"noraneko.nma.hash_state"`
  to `"floorp.nma.hash_state"` — see critical notes below

---

## ⚠️ Critical notes

Three things that must be correct for NMA to work safely:

1. **`registerNMAResource` ordering** — must be called *before*
   `loadEnabledModules()`. If it runs after, `jar:` URL resolution fails
   silently and modules don't load.

2. **`state.loader.isActive` atomicity** — the sequence
   `verifyNMA → readManifest → isActive = true` must not be interrupted or
   reordered. Setting `isActive` before verification completes would allow
   unverified modules to be loaded.

3. **Pref key collision** — if `PREF_HASH_STATE` stays as
   `"noraneko.nma.hash_state"`, Floorp and noraneko share the same preference
   on any system where both are installed. Rename to `"floorp.nma.hash_state"`
   before enabling NMA in production.

---

## Pointers

- **Upstream NMA source**: `bridge/loader-features/loader/nma/` in
  [`f3liz-dev/noraneko`](https://github.com/f3liz-dev/noraneko), branch
  `rftr-bridge`
- **Architecture analysis** (DAG levels, category-theoretic formalization,
  "what would break" notes):
  `~/.mio/notes/noraneko-nma-structure.md`
- **Merge strategy and full roadmap**:
  `~/.myu/notes/noraneko-floorp-merge.md`
- **Session resume notes** (Phase A context):
  `~/.myu/notes/noraneko-floorp-resume.md`

---

## File: browser-features/skin/fluerial/README.md

# Floorp Fluent UI (floorplegacy)

## Used Files

css/fluerial.css (test_legacy.css) icons/menu.svg (menu.svg) icons/newtab.svg
(newtab.svg) icons/material.svg (material.svg) icons/bookmark.svg
(../fluentUI/bookmark.svg)

## License

https://github.com/Floorp-Projects/Floorp-core/blob/65fbcaacfb08d16f5bf5c98ce1343d1b1bc54377/browser/themes/designs/floorp-legacy/test_legacy.css

MPL2.0

---

## File: browser-features/modules/modules/chrome-web-store/polyfills/README.md

# Chrome API Polyfills for Firefox

This directory contains polyfill implementations for Chrome extension APIs that are not natively supported in Firefox. These polyfills are automatically injected during Chrome extension conversion to provide compatibility.

## Purpose

Polyfills in this directory:
- Emulate Chrome-specific APIs using Firefox capabilities
- Are automatically injected during CRX to XPI conversion
- Provide transparent compatibility for extension developers
- Maintain API compatibility with Chrome's implementation

## Available Polyfills

### Offscreen API Polyfill

**File:** `OffscreenPolyfill.sys.mts`  
**Status:** Draft - Not yet integrated  
**Chrome API:** `chrome.offscreen`  
**Investigation:** [docs/investigations/offscreen-api-support.md](../../../../docs/investigations/offscreen-api-support.md)

**Description:**  
Provides compatibility for Chrome's Offscreen API by creating hidden iframes in Firefox MV3 background scripts. The Offscreen API allows extensions to run DOM-based operations in hidden background contexts.

**How it works:**
- Creates hidden iframes to emulate offscreen documents
- Leverages Firefox MV3 background scripts' DOM access
- Provides same API surface as Chrome's Offscreen API
- Enforces same constraints (single document, lifecycle rules)

**Usage:**
```javascript
// This code works in both Chrome and Firefox with the polyfill
await chrome.offscreen.createDocument({
  url: 'offscreen.html',
  reasons: ['DOM_PARSER'],
  justification: 'Parse HTML content'
});

// Use the offscreen document via message passing
// ...

await chrome.offscreen.closeDocument();
```

**Limitations:**
- Only works in contexts with DOM access (background scripts)
- Won't work in pure service worker contexts
- Slight lifecycle differences vs. Chrome
- Performance may differ from native implementation

---

### DocumentId Polyfill

**Directory:** `documentId/`  
**Status:** Draft - Not yet integrated  
**Chrome API:** `documentId` property in `chrome.scripting` and `chrome.tabs`

**Description:**  
Provides compatibility for Chrome's `documentId` property (introduced in Chrome 106+) by generating synthetic documentIds based on `tabId` and `frameId`. Wraps `chrome.scripting.executeScript()` and `chrome.tabs.sendMessage()` to translate documentIds to Firefox-compatible parameters.

**How it works:**
- Generates unique documentIds in format: `floorp-doc-{tabId}-{frameId}-{instanceId}`
- Intercepts API calls with `documentIds` and converts to `tabId`/`frameId` pairs
- Caches parsed documentIds for efficient lookups

**Usage:**
```javascript
// This code works in both Chrome and Firefox with the polyfill
await chrome.scripting.executeScript({
  target: { documentIds: ['floorp-doc-123-0-abc123'] },
  func: () => console.log('Executed!')
});

// With tabs.sendMessage
await chrome.tabs.sendMessage(tabId, message, {
  documentId: 'floorp-doc-123-0-abc123'
});
```

**Limitations:**
- DocumentIds are synthetic and may not persist across browser restarts
- Not fully compatible with all Chrome documentId use cases
- Event handler documentId injection not yet implemented

## Integration with Extension Conversion

### Current State

Polyfills are currently **not integrated** into the conversion pipeline. They are reference implementations showing how compatibility could be achieved.

### Planned Integration

1. **Manifest Transformation** (`ManifestTransformer.sys.mts`):
   - Detect when polyfilled APIs are requested
   - Inject polyfill scripts into background context
   - Mark manifest with polyfill metadata

2. **Build Integration** (`CRXConverter.sys.mts`):
   - Bundle polyfill scripts with converted extension
   - Place polyfills in `__floorp_polyfills__/` directory
   - Ensure polyfills load before extension code

3. **Permission Handling** (`Constants.sys.mts`):
   - Move polyfilled permissions to `POLYFILLED_PERMISSIONS`
   - Remove from `UNSUPPORTED_PERMISSIONS`
   - Allow permission during conversion

## Creating New Polyfills

When creating a new polyfill:

1. **Research** - Create investigation document in `docs/investigations/`
2. **Implementation** - Create polyfill module following this template:
   ```typescript
   /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
    * This Source Code Form is subject to the terms of the Mozilla Public
    * License, v. 2.0. If a copy of the MPL was not distributed with this
    * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
   
   /**
    * <API Name> Polyfill for Firefox
    *
    * Description...
    * See: docs/investigations/<api-name>-support.md
    */
   
   // Types
   export interface APIInterface {
     // ...
   }
   
   // Implementation
   class APIPolyfillImpl implements APIInterface {
     // ...
   }
   
   // Installation
   export function installAPIPolyfill(): boolean {
     // ...
   }
   ```

3. **Documentation** - Document:
   - What Chrome API it polyfills
   - How it works internally
   - Known limitations
   - Usage examples
   - Testing approach

4. **Testing** - Create tests:
   - Unit tests for polyfill logic
   - Integration tests with sample extensions
   - Real-world extension testing

5. **Integration** - Update:
   - `Constants.sys.mts` - Permission lists
   - `ManifestTransformer.sys.mts` - Injection logic
   - `CRXConverter.sys.mts` - Build integration

## Guidelines

### API Compatibility

- **Match Chrome's API surface** - Same method names, parameters, return types
- **Match Chrome's behavior** - Same constraints, errors, edge cases
- **Document differences** - Clearly note any unavoidable differences

### Performance

- **Minimize overhead** - Polyfills should be lightweight
- **Lazy initialization** - Don't create resources until needed
- **Cleanup** - Properly dispose of resources

### Error Handling

- **Match Chrome's errors** - Same error messages and conditions
- **Fail gracefully** - Provide helpful error messages
- **Don't break extensions** - Errors shouldn't crash the extension

### Code Quality

- **TypeScript** - Use proper type definitions
- **Documentation** - Comprehensive JSDoc comments
- **Testing** - Unit and integration tests
- **Linting** - Follow project code style

## Testing Polyfills

### Unit Tests

Test polyfill logic in isolation:
```typescript
// Test basic functionality
await polyfill.createDocument({ /* ... */ });
assert(await polyfill.hasDocument());
await polyfill.closeDocument();
assert(!(await polyfill.hasDocument()));
```

### Integration Tests

Test with real extensions:
1. Find Chrome extensions using the API
2. Convert using Floorp's CRX converter
3. Install and test functionality
4. Verify API compatibility

### Real-world Testing

Test with popular extensions:
- Extensions with many users
- Extensions using the API heavily
- Extensions with different use cases

## Maintenance

### Monitoring Chrome Changes

- Watch Chrome release notes for API changes
- Update polyfills when Chrome changes behavior
- Test compatibility with new Chrome versions

### Monitoring Firefox Changes

- Track Firefox's MV3 implementation
- Adapt polyfills to Firefox changes
- Watch for new native APIs that could replace polyfills

### Performance Monitoring

- Benchmark polyfill performance
- Compare with native implementation
- Optimize hot paths

## Future Work

### Potential Future Polyfills

Based on extension usage patterns, consider polyfills for:
- `chrome.sidePanel` - Chrome's side panel API
- `chrome.tabCapture` - Tab audio/video capture
- Other highly-requested Chrome APIs

### Native API Migration

If Firefox adds native support for an API:
1. Update polyfill to detect native API
2. Use native API when available
3. Keep polyfill for older Firefox versions
4. Eventually deprecate polyfill

## Resources

- [Chrome Extension APIs](https://developer.chrome.com/docs/extensions/reference/)
- [Firefox WebExtensions API](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions)
- [Browser Extension Polyfills](https://github.com/mozilla/webextension-polyfill)
- [Floorp Investigations](../../../../docs/investigations/)

---

## File: browser-features/chrome/common/pwa/README.md

# PWA

PWA stands for Progressive Web App, which is a technology that allows web pages available in modern browsers to be used like applications.

## What is PWA on Floorp?

Floorp realizes PWA by refactoring Firefox's code, utilizing the SSB (Site Specific Browser) feature that Firefox provided.

For example, ManifestProcesser.ts is written with reference to Firefox code, and functions with the same name exist.

## Architecture Overview

The PWA feature consists mainly of two parts:

1. **Frontend part** (`src/apps/main/core/common/pwa/`)

   - UI elements (SsbPageAction, SsbPanelView)
   - PWA window management
   - High-level service API

2. **Backend part** (`src/apps/modules/src/modules/pwa/`)
   - Command line integration
   - Data storage
   - OS integration features

## Main Components

- **PwaService**: Central service class. Integrates other components and provides high-level API
- **SiteSpecificBrowserManager**: Responsible for PWA installation and management
- **SsbRunner**: Handles launching PWA windows
- **DataManager**: Manages information of installed PWAs
- **ManifestProcesser**: Extracts and processes PWA information from web manifests

## OS Integration

Currently, the following integration features are available on the Windows platform:

- Pinning to the taskbar
- Launching in dedicated windows
- Icon integration

On macOS, launcher bundles are created in `~/Applications/Floorp Apps/`.
Each bundle contains an executable launcher, `Info.plist`, and a 512px ICNS icon.
The launcher passes the installing profile and SSB ID to Floorp. Bundle identity
includes the profile, so copied SSB IDs in different profiles do not collide.
Opening an existing PWA from Floorp also creates or repairs its launcher.
Renaming or uninstalling a PWA updates or removes its owned bundle.

This is launcher integration: it does not automatically pin apps to the Dock
or provide a separate native process/Dock identity for each running PWA.
On macOS, verify Finder launch with Floorp both running and closed, manual Dock
pinning, icon display, rename/uninstall, and two profiles before release.
File-generation tests on other platforms do not verify Launch Services behavior.

PWA regression tests are colocated under `test/` and under
`browser-features/modules/modules/pwa/supports/test/`. They cover toolbar
preferences (including existing configurations and live changes), legacy SSB
data migration, launcher metadata, profile isolation, bundle repair/removal,
and fallback icon encoding. Run with `deno task test --near <directory>` in
an isolated test profile.

## Directory Structure

```plaintext
src/apps/main/core/common/pwa/
├── config.ts             # Configuration options
├── dataStore.ts          # Data persistence
├── default-pref.ts       # Default settings
├── iconProcesser.ts      # Icon processing
├── imageTools.ts         # Image processing utilities
├── index.ts              # Main entry point
├── manifestProcesser.ts  # Manifest processing
├── pwa-window.tsx        # PWA window UI
├── pwaService.ts         # Central service
├── SsbPageAction.tsx     # URL bar PWA action
├── SsbPanelView.tsx      # PWA management panel
├── ssbManager.ts         # SSB management
├── ssbRunner.ts          # SSB execution
└── type.ts               # Type definitions

src/apps/modules/src/modules/pwa/
├── DataStore.sys.mts           # System-level data store
├── SsbCommandLineHandler.sys.mts # Command line integration
├── ImageTools.sys.mts          # Image processing utilities
├── supports/                   # OS-specific support features
└── type.ts                     # Type definitions
```

## Developer Information

To extend the PWA functionality, you mainly need to understand the following files:

- `pwaService.ts`: Adding/changing service APIs
- `ssbManager.ts`: Extending installation and management features
- `manifestProcesser.ts`: Customizing manifest processing
- `SsbPageAction.tsx`/`SsbPanelView.tsx`: Customizing UI elements

To add support for a new platform, implement it in the `supports/` directory.

---

## File: browser-features/chrome/common/reverse-sidebar-position/README.md

# Reverse Sidebar Position

Currently there is no sidebar impl, so this codes has no effect.

---

## File: browser-features/chrome/README.md

# @nora/core

When build, placed on noraneko/content

This component handles almost all of Noraneko's core code.

For menu customization behavior and settings, see the
[context menu customization guide](../../docs/context-menu-customization.md).

If you are to make feature modifying preferences, or other internal html, go to
`root/apps/main/about/`.

## Directory Structure

common/

- main codes
- supports hot reload

static/

- codes that can't be hot-reloaded

nora/

- codes that requires noraneko-runtime (esp. cpp patch)
- should be disabled easily for other-runtime

utils/

- Utilities that helps you to code comfortable.
- It is preferred that single file but folder with index.ts can be in.

example/

- as test and template for basic codes

---

## File: docs/development/directories/browser-features/modules/browser-glue.mdx

---
title: "BrowserGlue & Window Actors"
sidebar_label: "BrowserGlue"
floorp_commit: "9955ae2e96646d1e323c241fa738b06ea33cf553"
generated: true
---
# BrowserGlue & Window Actors

This page is intentionally seeded before Codex rewrites it from the source inventory and allowed source files.

## Source Anchors

- Firefox Base: `static/gecko/pref/override.ini`
- ESM Modules: `browser-features/modules/modules/BrowserGlue.sys.mts`
- Bridge: `bridge/startup/src/chrome_root.ts`
- Chrome UI: `browser-features/chrome/common/mod.ts`
- Pages: `browser-features/pages-settings/vite.config.ts`
- Loader entrypoint: `bridge/loader-features/loader/index.ts`
- Loader module registry: `bridge/loader-features/loader/modules.ts`
- Loader module hooks: `bridge/loader-features/loader/modules-hooks.ts`
- Chrome feature overview: `browser-features/chrome/README.md`
- Static chrome feature discovery: `browser-features/chrome/static/mod.ts`
- Gecko version configuration: `static/gecko/config/README.md`
- Settings app entry: `browser-features/pages-settings/src/main.tsx`
- Settings routes: `browser-features/pages-settings/src/App.tsx`
- Browser test runner: `tools/src/colocated_test_runner.ts`
- Browser test result collector: `tools/src/browser_test_collector.ts`
- Development inspection CLI: `tools/dev-tool.ts`
- Build CLI: `tools/feles-build.ts`
- Root Deno tasks: `deno.json`
- Chrome feature discovery: `browser-features/chrome/common/mod.ts`
- Window Actors: `browser-features/modules/modules/BrowserGlue.sys.mts`
- Bridge loader: `bridge/startup/src/chrome_root.ts`
- Loader dev server: `bridge/loader-features/vite.config.ts`

---

## File: docs/development/directories/browser-features/modules/overview.mdx

---
title: "Modules Overview"
sidebar_label: "Overview"
floorp_commit: "9955ae2e96646d1e323c241fa738b06ea33cf553"
generated: true
---
# Modules Overview

This page is intentionally seeded before Codex rewrites it from the source inventory and allowed source files.

## Source Anchors

- Firefox Base: `static/gecko/pref/override.ini`
- ESM Modules: `browser-features/modules/modules/BrowserGlue.sys.mts`
- Bridge: `bridge/startup/src/chrome_root.ts`
- Chrome UI: `browser-features/chrome/common/mod.ts`
- Pages: `browser-features/pages-settings/vite.config.ts`
- Loader entrypoint: `bridge/loader-features/loader/index.ts`
- Loader module registry: `bridge/loader-features/loader/modules.ts`
- Loader module hooks: `bridge/loader-features/loader/modules-hooks.ts`
- Chrome feature overview: `browser-features/chrome/README.md`
- Static chrome feature discovery: `browser-features/chrome/static/mod.ts`
- Gecko version configuration: `static/gecko/config/README.md`
- Settings app entry: `browser-features/pages-settings/src/main.tsx`
- Settings routes: `browser-features/pages-settings/src/App.tsx`
- Browser test runner: `tools/src/colocated_test_runner.ts`
- Browser test result collector: `tools/src/browser_test_collector.ts`
- Development inspection CLI: `tools/dev-tool.ts`
- Build CLI: `tools/feles-build.ts`
- Root Deno tasks: `deno.json`
- Chrome feature discovery: `browser-features/chrome/common/mod.ts`
- Window Actors: `browser-features/modules/modules/BrowserGlue.sys.mts`
- Bridge loader: `bridge/startup/src/chrome_root.ts`
- Loader dev server: `bridge/loader-features/vite.config.ts`