Replies: 1 comment
-
Hello, did you find a solution to your issue or you still need help? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi all, I'm developing an EPUB reader app using SwiftUI and the Readium Swift Toolkit (latest stable release: 3.2.0). My goal is to inject custom JavaScript into the EPUB navigator's web view to handle word selection for a Japanese dictionary lookup feature (note, I tried using
VisualNavigator
'sdidTapAt
functionality, but I couldn't figure out how to reliably map the tap gesture coordinates on the screen to the WebView).I'm trying to use the standard mechanism provided by
EPUBNavigatorDelegate
: thenavigator(_:setupUserScripts userContentController: WKUserContentController)
method. However, despite extensive troubleshooting, this specific delegate method is never being called.I've confirmed that:
EPUBNavigatorViewController
's delegate property IS being successfully assigned to myCoordinator
instance within themakeUIViewController
method of myUIViewControllerRepresentable
. Logs confirm the assignment happens and both the navigator and coordinator instances are valid at that point.EPUBNavigatorDelegate
(specificallynavigator(_:locationDidChange:)
) ARE being called correctly when I navigate the publication. This confirms the fundamental delegate connection is established.Coordinator
conforms toEPUBNavigatorDelegate
and implements thenavigator(_:setupUserScripts:)
method (with logging inside, which never appears).In terms of troubleshooting, I've:
EPUBNavigatorViewController.Configuration()
during initialization.evaluateJavaScript
after the firstlocationDidChange
. This did execute the JS but failed withTypeError: window.R2NAVIGATOR_SEND_MESSAGE is not a function
, indicating the Readium JS bridge wasn't set up at that point (likely because the proper setup phase involvingsetupUserScripts
was skipped, though I'm admittedly not 100% sure about this).My question is, given that the delegate is correctly assigned and other delegate methods are functioning, why might the
navigator(_:setupUserScripts:)
method specifically not be called during the EPUBNavigatorViewController's setup? Are there known conditions, configurations, or specific timing issues related to the internalPaginationView
orEPUBSpreadView
creation that could cause this hook to be skipped?Is there an alternative, reliable way within the Readium framework to inject WKUserScripts or otherwise execute custom JavaScript reliably before the EPUB content fully loads its own scripts, if
setupUserScripts
proves unreliable in my case?Any insights or suggestions would be greatly appreciated! Thanks.
Environment:
Readium Swift Toolkit Version: 3.2.0
Xcode Version: 16.3
Target OS: iOS 18.0
Beta Was this translation helpful? Give feedback.
All reactions