Skip to content

Commit

Permalink
WIP: WASM compatibility updates/CORS override for GitHub Pages
Browse files Browse the repository at this point in the history
  • Loading branch information
espresso3389 committed Feb 13, 2025
1 parent 39042d9 commit 6db7f94
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
- name: Build Flutter Web App (WASM)
run: |
cd example/viewer/
cp -f extras/github-pages/* web/
flutter build web --wasm --release
sed -i 's|<base href="/">|<base href="/pdfrx/">|' build/web/index.html
- name: Configure Git for deployment
run: |
git config user.email "[email protected]"
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# CHANGELOG

# 1.1.2
## 1.1.2

- FIXED: if running with WASM enabled on Flutter Web, certain PDF file could not be loaded correctly
- Debug log to know WASM/SharedArrayBuffer status on Flutter Web
Expand Down
2 changes: 2 additions & 0 deletions example/viewer/extras/github-pages/coi-serviceworker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions example/viewer/extras/github-pages/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<base href="/pdfrx/">

<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="pdfrx demo page">
<meta name="viewport" content="width=device-width,initial-scale=1">

<!-- iOS meta tags & icons -->
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="example">
<link rel="apple-touch-icon" href="icons/Icon-192.png">

<!-- Favicon -->
<link rel="icon" type="image/png" href="favicon.png"/>

<title>pdfrx demo page</title>
<link rel="manifest" href="manifest.json">

<!-- Workaround for GitHub Pages CORS policy
https://github.com/gzuidhof/coi-serviceworker -->
<script>
window.coi = {coepCredentialless: () => true,}
</script>
<script src="coi-serviceworker.min.js"></script>
</head>
<body>
<script src="flutter_bootstrap.js" async></script>
</body>
</html>
2 changes: 1 addition & 1 deletion lib/src/web/pdf.js.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ extension type PdfjsDocument._(JSObject _) implements JSObject {
external void destroy();

external JSPromise<JSNumber> getPageIndex(PdfjsRef ref);
external JSPromise<JSObject> getDestination(String id);
external JSPromise<JSObject?> getDestination(String id);
external JSPromise<JSArray<PdfjsOutlineNode>?> getOutline();
}

Expand Down
3 changes: 1 addition & 2 deletions lib/src/web/pdfrx_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ class PdfDocumentWeb extends PdfDocument {
Future<JSObject?> _getDestObject(JSAny? dest) async {
if (dest == null) return null;
if (dest.isA<JSString>()) {
final destObj = await _document.getDestination((dest as JSString).toDart).toDart;
return destObj;
return await _document.getDestination((dest as JSString).toDart).toDart;
} else {
return dest as JSObject;
}
Expand Down

0 comments on commit 6db7f94

Please sign in to comment.