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
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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'sdidTapAtfunctionality, 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 myCoordinatorinstance within themakeUIViewControllermethod 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.Coordinatorconforms toEPUBNavigatorDelegateand implements thenavigator(_:setupUserScripts:)method (with logging inside, which never appears).In terms of troubleshooting, I've:
EPUBNavigatorViewController.Configuration()during initialization.evaluateJavaScriptafter 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 involvingsetupUserScriptswas 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 internalPaginationVieworEPUBSpreadViewcreation 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
setupUserScriptsproves 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