Skip to content

[webview_flutter] Calling setOnConsoleMessage multiple times throws #180914

Closed
flutter/packages
#10922

Description

@limonadev

Use case

  1. Create a WebViewController
  2. Register the callback for console messages with setOnConsoleMessage
  3. If the same controller is reused later and we try to register the same callback with setOnConsoleMessage it's going to throw an Exception.

There is no real way to avoid this as there is no way to unregister that channel.

Proposal

To add a new method in the WebViewController class to unregister the one created by setOnConsoleMessage.

A workaround for this is to manually call:

webViewController.removeJavaScriptChannel(
  'fltConsoleMessage', // this is the channel name according to source code
);

Activity

  1. added
    in triagePresently being triaged by the triage team
    c: proposalA detailed proposal for a change to Flutter
    c: new featureNothing broken; request for a new capability
    packageflutter/packages repository. See also p: labels.
    and removed
    in triagePresently being triaged by the triage team
    on Jan 14, 2026
  2. stuartmorgan-g commented on Jan 14, 2026

    @stuartmorgan-g
    Contributor

    The JavaScript channel is an implementation detail, on one specific platform. It's not part of the API surface, so a way to unregister the channel as public API doesn't really make sense.

    Rather than jumping to a specific proposed solution, what is the actual thing you want to be able to do? Is it just for setOnConsoleMessage to be callable multiple times?

  3. limonadev commented on Jan 14, 2026

    @limonadev
    ContributorAuthor

    Yes, it's to be able to call setOnConsoleMessage on the same controller multiple times without throwing an exception

  4. added
    platform-iosiOS applications specifically
    platform-macosBuilding on or for macOS specifically
    and removed
    c: new featureNothing broken; request for a new capability
    c: proposalA detailed proposal for a change to Flutter
    on Jan 14, 2026
  5. changed the title [-]Add a way to unregister the JavaScript channel created by the method setOnConsoleMessage[/-] [+][webview_flutter] Calling `setOnConsoleMessage` multiple times throws[/+] on Jan 14, 2026
  6. stuartmorgan-g commented on Jan 14, 2026

    @stuartmorgan-g
    Contributor

    Updated title and labels to clarify that this is actually a bug report, rather than a feature request.

    (In the future, please report bugs—such as unexpected exceptions being thrown—as bugs, rather than filing a proposed fix for the bug as a feature request.)

  7. added
    P2Important issues not at the top of the work list
    on Jan 20, 2026
  8. limonadev commented on Jan 21, 2026

    @limonadev
    ContributorAuthor

    Just a bit of extra information. I think the idea would be to be able to call setOnConsoleMessage multiple times but without getting multiple messages at the same time (that's why I mentioned it would be ideal to have a way to "unregister" the callback)

  9. rickhohler commented on Jan 29, 2026

    @rickhohler

    I'll take a look at this.

  10. rickhohler commented on Jan 29, 2026

    @rickhohler

    I have submitted a fix for this issue in flutter/packages#10922

  11. github-actions commented on Mar 7, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  12. locked as resolved and limited conversation to collaborators on Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listp: webviewThe WebView pluginpackageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyplatform-macosBuilding on or for macOS specificallyteam-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions