[Bug]: ERR_FILE_NOT_FOUND: package_info_plus not working on Flutter web deployed as chrome extension
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:
- Run
flutter build web --release --web-renderer html --csp - In Chrome/Edge go to the extensions page (
chrome://extensionsoredge://extensions). - Enable Developer Mode.
- Load the build/web directory to your browser.
- Open new tab and check the text.
- Instead of printing the version on screen, there's an error:
FILE_NOT_FOUNDin 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
- [X] I Google'd a solution and I couldn't find it
- [X] I searched on StackOverflow for a solution and I couldn't find it
- [X] I read the README.md file of the plugin
- [X] I'm using the latest version of the plugin
- [X] All dependencies are up to date with
flutter pub upgrade - [X] I did a
flutter clean - [X] I tried running the example project
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
Commenting to keep it active!
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.
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
Commenting to keep this from becoming stale!
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
Commenting AGAIN to keep this from becoming stale!
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
Commenting AGAIN to keep this from becoming stale!
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: https://github.com/fluttercommunity/plus_plugins/issues/2732#issuecomment-2006489027)
Hi, in this PR https://github.com/fluttercommunity/plus_plugins/pull/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
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
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.
Ah! I see. That makes sense! I tried that and it seems to be working just fine!
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.
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