ChromeXt icon indicating copy to clipboard operation
ChromeXt copied to clipboard

Userscripts not loading in iframes

Open gpourbaix opened this issue 2 years ago • 3 comments

Hello

Thanks for you module, it's working very nicely.

I have noticed that userscripts are not invoked in iframes. Is it possible to do something about it ?

Best regards,

gpourbaix avatar Nov 21 '23 16:11 gpourbaix

No, currently this is not implemented yet, and I probably have no time to do it in this year. For anyone who is interested in implementing this function, please refer to my commenst (the fourth point): https://github.com/JingMatrix/ChromeXt/issues/104#issuecomment-1720721689

JingMatrix avatar Nov 21 '23 17:11 JingMatrix

Thank for your reply. I did not manage to use CDP in iframe and i felt that it was less stable for main pages.

Just an idea : maybe you could hook shouldInterceptRequest to inject the userscript ? I found an example on stackoverflow :  https://stackoverflow.com/questions/68984756/how-do-i-inject-javascript-to-an-iframe-from-java-code-into-an-android-webview

I'm not an android developper even less an xposed module developper so it's too difficult to do it myself, i've already had a hard time just to compile the code ^^

gpourbaix avatar Nov 22 '23 11:11 gpourbaix

Once you have configured properly the JDK version (see #125), it should be easy to compile.

As for your idea, it is indeed given in the issue of which I cited my own comment above, though the issue was written in Chinese. If you are using a WebView browser, you can try hook the shouldInterceptRequest method, see the file WebView.kt . (As for chromium browsers, one has to use CDP.)

I believe the logic of WebView.kt is fairly clear, where I hooked the onPageStarted method: https://github.com/JingMatrix/ChromeXt/blob/b969aaff44764bd3807816ef4fe7e8b2dc2b59da/app/src/main/java/org/matrix/chromext/hook/WebView.kt#L76-L78 You may try to understand it and thus contribute to ChromeXt ;)

JingMatrix avatar Nov 22 '23 12:11 JingMatrix