Repository navigation
Run host scripts in web pages, and show pages only once they are ready - #52
Merged
Merged
Conversation
GaplessAsset.javaScript runs in every document a web asset loads, at document start through WebViewCompat.addDocumentStartJavaScript: before the page's own scripts and its first paint, so a hidden cookie banner never flashes up. It is limited to the page's own origin unless javaScriptOrigins allows more, removed when the slot moves on, and on WebView versions before 87 runs at the first paint instead. waitForPageReady holds the cut until the page calls gapless.ready(), for dashboards that paint before their data arrives. A page that never calls it is shown when play() stops waiting, like a page that never paints. The sample app gets pages that check both (web_script_check, web_ready_8s, web_ready_never) in a web_scripts playlist, consent banner hiding on the news sites, a ready-and-scroll script on Wikipedia, and --ez scripts false to compare without them. Adds androidx.webkit 1.18.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two additions for web assets, both opt-in per asset.
Page scripts
GaplessAsset.javaScriptruns in every document the page loads, at document start (WebViewCompat.addDocumentStartJavaScript): before the page's own scripts and before anything is drawn. Styles it adds apply from the first paint, so a hidden cookie banner or scrollbar never flashes up. It runs again on each navigation and refresh. Typical uses: hiding banners, fitting a page to the screen, signing in, scrolling.javaScriptOriginsallows others, orsetOf("*")all. Non-http pages allow every origin by default.Pages that say when they are ready
With
waitForPageReady = truea page is ready to be shown when it callsgapless.ready(), not when it first paints, for dashboards and sign-ins that paint before they have anything to show. The page orjavaScriptmakes the call. The page loads while the asset before it plays, so it is normally ready by its turn; one that never calls it is shown whenplay()stops waiting, as an unpainted page is.gaplessis aJavascriptInterfaceon both WebViews; any page can callready(), but all it decides is when the page is shown.Sample app
web_script_check: the injected script marks that it ran and hides a fake red cookie banner; the page turns green with SCRIPT RAN FIRST, or red NO SCRIPT with the banner.web_ready_8s: red LOADING, then after 8 seconds green READY andgapless.ready(), longer than the 6-second clip it preloads behind.web_ready_never: never ready, for the timeout path.web_scriptsplaylist.--ez scripts falsedrops every script and readiness wait, to compare.Checked on the TV (WebView 157), screenshots with and without
web_script_checkweb_ready_8s, 0.3 s after it went on screenready())The live news sites show this TV no consent banner even without the script, so they couldn't confirm the banner hiding; the local check page does.
Robolectric tests cover readiness (not ready at the paint, ready before the paint, the timeout path, plain pages) and the at-paint script path with its origin check. They caught the bridge posting through
view.post, which does nothing for a view not attached to a window; it uses a main-thread handler now.Adds
androidx.webkit1.18.0 (released 2026-10-21).