Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: ERR_FILE_NOT_FOUND: package_info_plus not working on Flutter web deployed as chrome extension #1409

Closed
7 tasks done
BirjuVachhani opened this issue Dec 19, 2022 · 16 comments
Labels
bug Something isn't working Stale triage

Comments

@BirjuVachhani
Copy link

Platform

Web (chrome & Edge)

Plugin

package_info_plus

Version

3.0.2 (latest)

Flutter SDK

3.3.10

Steps to reproduce

Run the sample code on flutter web deployed as chrome extension

Deploying as chrome extension:

  1. Run flutter build web --release --web-renderer html --csp
  2. In Chrome/Edge go to the extensions page (chrome://extensions or edge://extensions).
  3. Enable Developer Mode.
  4. Load the build/web directory to your browser.
  5. Open new tab and check the text.
  6. Instead of printing the version on screen, there's an error: FILE_NOT_FOUND in the console and it never shows the version.

If the same thing is done with a normal run of the project with flutter run web then it works perfectly. It just doesn't work on web builds deployed as browser extension.

According to the error in. the console, it seems like the base uri for version.json file is incorrect in this case.

Code Sample

### main.dart


import 'package:flutter/material.dart';
import 'package:package_info_plus/package_info_plus.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: MyWidget(),
        ),
      ),
    );
  }
}

class MyWidget extends StatefulWidget {
  const MyWidget({super.key});

  @override
  State<MyWidget> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyWidget> {
  String? version;

  @override
  void initState() {
    super.initState();
    fetchVersion();
  }

  @override
  Widget build(BuildContext context) {
    return Text(
      version ?? 'Loading...',
      style: Theme.of(context).textTheme.headline4,
    );
  }

  Future<void> fetchVersion() async {
    final PackageInfo info = await PackageInfo.fromPlatform();
    setState(() => version = info.version);
  }
}


### web/manifest.json

```json
{
  "name": "Test Project",
  "description": "A is a description.",
  "version": "0.1.1",
  "manifest_version": 3,
  "short_name": "test",
  "content_security_policy": {
    "content_security_policy": {
      "extension_pages": "script-src 'self' ; object-src 'self'"
    }
  },
  "chrome_url_overrides": {
    "newtab": "index.html"
  },
  "icons": {
    "128": "icon128.png"
  }
}


### Logs

```shell
GET chrome-extension://nfdiokdbeccelflpphpogdaendmlkfoi/index.html/version.json?cachebuster=1671427592603 net::ERR_FILE_NOT_FOUND

Flutter Doctor

[✓] Flutter (Channel stable, 3.3.10, on macOS 13.1 22C65 darwin-arm, locale en-IN)
    • Flutter version 3.3.10 on channel stable at /Users/birjuvachhani/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 135454af32 (4 days ago), 2022-12-15 07:36:55 -0800
    • Engine revision 3316dd8728
    • Dart version 2.18.6
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc1)
    • Android SDK at /Users/birjuvachhani/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0-rc1
    • Java binary at: /Users/birjuvachhani/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14C18
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Users/birjuvachhani/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9014738/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] Android Studio (version 2021.3)
    • Android Studio at /Users/birjuvachhani/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/213.7172.25.2113.9123335/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] IntelliJ IDEA Community Edition (version 2022.2.3)
    • IntelliJ at /Users/birjuvachhani/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/222.4345.14/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] IntelliJ IDEA Community Edition (version 2022.3)
    • IntelliJ at /Users/birjuvachhani/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/223.7571.182/IntelliJ IDEA CE.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] VS Code (version 1.74.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.52.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.1 22C65 darwin-arm
    • Chrome (web)    • chrome • web-javascript • Google Chrome 108.0.5359.124

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

Checklist before submitting a bug

  • I Google'd a solution and I couldn't find it
  • I searched on StackOverflow for a solution and I couldn't find it
  • I read the README.md file of the plugin
  • I'm using the latest version of the plugin
  • All dependencies are up to date with flutter pub upgrade
  • I did a flutter clean
  • I tried running the example project
@BirjuVachhani BirjuVachhani added bug Something isn't working triage labels Dec 19, 2022
@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days

@github-actions github-actions bot added the Stale label Mar 20, 2023
@BirjuVachhani
Copy link
Author

Commenting to keep it active!

@github-actions github-actions bot removed the Stale label Mar 21, 2023
@jglatre
Copy link

jglatre commented May 29, 2023

I'm facing the same issue when I deploy a flutter app as a CDN resource, i.e. just a <script> element pointing to an external http url. It turns out the culprit is a window.document.baseUri in method getAll of PackageInfoPlusWebPlugin. Obviously it won't work unless both <script> and <base> elements point to the same source, which in my case is not the point.

It would be nice to have a way to parameterize that baseUri, but I can't think of how it can fit in the platform agnostic interface. If I find a workaround I'll post it here.

@github-actions
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days

@github-actions github-actions bot added the Stale label Aug 28, 2023
@BirjuVachhani

This comment was marked as off-topic.

@github-actions github-actions bot removed the Stale label Aug 29, 2023
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days

@github-actions github-actions bot added the Stale label Nov 27, 2023
@BirjuVachhani

This comment was marked as off-topic.

@github-actions github-actions bot removed the Stale label Nov 28, 2023
Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days

@github-actions github-actions bot added the Stale label Feb 27, 2024
@BirjuVachhani

This comment was marked as off-topic.

@miquelbeltran
Copy link
Member

It would be nice to have a way to parameterize that baseUri, but I can't think of how it can fit in the platform agnostic interface. If I find a workaround I'll post it here.

Would be providing an optional parameter in static Future<PackageInfo> fromPlatform() with the custom version.json url enough to bypass this issue?

(same as I asked here: #2732 (comment))

@miquelbeltran
Copy link
Member

Hi, in this PR #2733 there is a potential fix for this issue. It has been merged to main, so before we do a release, I'd like to know if it solves your issue. Could you try the package using a git-reference? https://dart.dev/tools/pub/dependencies#git-packages

@BirjuVachhani
Copy link
Author

I checked with the latest version of packge_info_plus and it is working for me with the example code I gave above. I checked with your branch but I am not able to compile and run.

Dependency

dependencies:
  package_info_plus:
    git:
      url: https://github.com/AriasBros/plus_plugins.git
      path: packages/package_info_plus/package_info_plus
      ref: fix/issue-2732

Error

Target dart2js failed: ProcessException: Process exited abnormally with exit code 1:
../../../.pub-cache/git/plus_plugins-26bea2216715fdeed0d3f852573acd7d5c6219fd/packages/package_info_plus/package_info_plus/lib/package_info_plus.dart:81:7:
Error: No named parameter with the name 'baseUrl'.
      baseUrl: baseUrl,
      ^^^^^^^
Error: Compilation failed.
  Command: /Users/birjuvachhani/flutter/bin/cache/dart-sdk/bin/dart --disable-dart-dev
  /Users/birjuvachhani/flutter/bin/cache/dart-sdk/bin/snapshots/dart2js.dart.snapshot
  --platform-binaries=/Users/birjuvachhani/flutter/bin/cache/flutter_web_sdk/kernel --invoker=flutter_tool -Ddart.vm.product=true
  -DFLUTTER_WEB_AUTO_DETECT=false -DFLUTTER_WEB_USE_SKIA=false
  -DFLUTTER_WEB_CANVASKIT_URL=https://www.gstatic.com/flutter-canvaskit/a5c24f538d05aaf66f7972fb23959d8cafb9f95a/ --native-null-assertions --no-source-maps -o
  /Users/birjuvachhani/Documents/Projects/untitled3/.dart_tool/flutter_build/d5f3922e26da14c3f02eea3a334d2b37/app.dill --packages=.dart_tool/package_config.json
  --cfe-only /Users/birjuvachhani/Documents/Projects/untitled3/.dart_tool/flutter_build/d5f3922e26da14c3f02eea3a334d2b37/main.dart

@miquelbeltran
Copy link
Member

miquelbeltran commented Mar 25, 2024

You'll have to do the same with the package_info_plus_platform_interface included in the same repo, because the platform call method signature changed.

@BirjuVachhani
Copy link
Author

Ah! I see. That makes sense! I tried that and it seems to be working just fine!

@miquelbeltran
Copy link
Member

Thanks a lot for checking @BirjuVachhani !

Can I ask, did you use the baseUrl param? What value did you pass in the chrome extension? If you can show that, I want to understand better how this can be used for a chrome extension project.

Copy link

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days

@github-actions github-actions bot added the Stale label Jun 24, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Stale triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants