Skip to content

feat: add plugins.<Name>.disabled to skip registering a native plugin - #8615

Open
jtsnova wants to merge 8 commits into
ionic-team:mainfrom
jtsnova:feat/support-disabling-plugins
Open

jtsnova wants to merge 8 commits into
ionic-team:mainfrom
jtsnova:feat/support-disabling-plugins

Conversation

@jtsnova

@jtsnova jtsnova commented Sep 21, 2026 •

Copy link
Copy Markdown

Description

Adds a plugins.<PluginName>.disabled config option to prevent a native Capacitor plugin from being registered and loaded:

const config: CapacitorConfig = {
  plugins: {
    MyPlugin: {
      disabled: true,
    },
  },
};

The setting is read from the native capacitor.config.json generated by npx cap sync.

  • Android: Bridge.registerPlugin() and Bridge.registerPluginInstance() check the plugin configuration before creating a PluginHandle.
  • iOS: CapacitorBridge.loadPlugin(type:) checks the configuration before loading, registering, and exporting the plugin to JavaScript.

Change Type

  • Fix
  • Feature
  • Refactor
  • Breaking Change
  • Documentation

Rationale / Problems Fixed

There is currently no runtime configuration mechanism to prevent an installed native plugin from loading. This makes it difficult to selectively disable a plugin while retaining it as a project dependency or while sharing configuration across builds.

disabled is intentionally separate from enabled, because plugins such as CapacitorHttp and CapacitorCookies already use enabled with plugin-specific behavior.

Nothing changes unless plugins.<PluginName>.disabled is set to true. Plugins remain enabled by default.

Tests or Reproductions

  • npm run build --workspace @capacitor/cli completes successfully.
  • Changed TypeScript and Java files pass Prettier formatting checks.
  • Added Android configuration coverage for reading plugins.<PluginName>.disabled.
  • The Android unit-test suite could not be run in the current environment because the project requires Java 21 and the available JDK is older.

Platforms Affected

  • Android
  • iOS
  • Web

Notes / Comments

A disabled plugin is not registered, instantiated, loaded, or exported through the native bridge. Therefore, it is not exposed through native plugin headers and Capacitor.isPluginAvailable('MyPlugin') returns false.

@jtsnova jtsnova changed the title feat: add support for disabling plugins in configuration feat(cli): add support for disabling plugins in configuration Sep 21, 2026
@eric-horodyski

Copy link
Copy Markdown
Member

Hi! What would be the purpose of a disallow list vs the allowlist functionality that ships today (includePlugins)?

@jtsnova

jtsnova commented Oct 9, 2026

Copy link
Copy Markdown
Author

We currently rely on native code that uses Android's CookieManager, but the stored information is removed whenever the web application loads. As a result, we're looking for a way to block the loading of the core plugins (CapacitorCookies,CapacitorHttp ...) themselves.

If you know of an alternative approach, I'd be glad to try it.

@eric-horodyski

Copy link
Copy Markdown
Member

@jtsnova — those plugins shouldn't load unless you explicitly enable them. Could you share your capacitor.config.ts (or .json) file?

@jtsnova

jtsnova commented Oct 14, 2026

Copy link
Copy Markdown
Author

those plugins shouldn't load unless you explicitly enable them. Could you share your capacitor.config.ts (or .json) file?

Bridge has a mechanism that registers the core plugins. This ensures they are always properly instantiated through the registerAllPlugins function, which unconditionally registers all of them and loads them into memory.

What you mentioned about plugins only loading when explicitly enabled applies to third-party plugins, rather than the core plugins handled by Bridge.

@andredestro andredestro changed the title feat(cli): add support for disabling plugins in configuration feat: add plugins.<Name>.disabled to skip registering a native plugin Nov 25, 2026
@andredestro

Copy link
Copy Markdown
Contributor

Thanks @jtsnova! We'd like to ship this in the next 9.x minor, so I pushed a few changes on top:

  • Merged main, which moved the iOS sources to ios/Sources/ (this fixes the conflict).
  • iOS: fixed a compile error in registerPluginInstance and moved the check before the "Overriding" log.
  • iOS: for CapacitorHttp and CapacitorCookies, disabled: true now wins over enabled: true in exportCoreJS. Before, fetch was patched to call a plugin that wasn't registered, and those calls never settled.
  • Tests: replaced the config-only unit test with an Android instrumented test and an iOS XCTest that check a disabled plugin isn't registered.
  • Docs: documented disabled in PluginConfig (including how to set it for plugins that declare their own config type) and the difference between enabled and disabled in http.md and cookies.md.

Notes for reviewers:

  • This is marked @since 9.1.0, so it should be merged after 9.0.0 is out.
  • CI only runs the Android unit tests, so I ran DisabledPluginTest locally on an emulator.
  • I also checked it in a sample app on iOS and Android: disabled plugins are unavailable, fetch isn't patched and nothing hangs. On Android, disabling CapacitorCookies keeps session cookies across Activity recreation.
  • fix(android): read CapacitorCookies/CapacitorHttp isEnabled from injected global #8745 changes the same patching check on Android. Whichever lands second needs Bridge.getJSInjector() to treat disabled as off.
  • I'll open the capacitor-docs PR for the config reference once this is merged.

disabled already wins over enabled for registration and for patching fetch,
XHR and document.cookie, but the HTTP interceptor still read only enabled, so
with both set a page script could call the proxy directly.

Also adds an iOS test for loading a disabled plugin by class name.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants