Phone: YouTube keeps playing, full screen fills the phone, nothing in front of it
- The phone's browser passes as a phone's Chrome all through (client hints, no automation flag): YouTube no longer stops a video a couple of minutes in with "something went wrong". - Full screen is done on the page: the element pinned over the phone's whole page, everything else hidden. The windowless browser refused the real thing or shifted it off to one side. Its window now matches the page too. - With the phone up at your face the tool belt, the tool plate and the hint line step aside. - Test: -demoyt (-demoytlong for the 200 s run). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -32,7 +32,27 @@ namespace GrassCutter
|
||||
"for(let i=0;i<frames.length;i++)try{frames[i].postMessage({__gc:[s.vol,s.hold]},'*')}catch(e){}},300);" +
|
||||
"addEventListener('message',e=>{const m=e.data&&e.data.__gc;if(m){s.vol=m[0];s.hold=m[1]}});" +
|
||||
"window.open=u=>{if(u)location.href=u;return window};" +
|
||||
"addEventListener('click',e=>{const a=e.target.closest&&e.target.closest('a[target]');if(a)a.target='_self'},true)})()";
|
||||
"addEventListener('click',e=>{const a=e.target.closest&&e.target.closest('a[target]');if(a)a.target='_self'},true)})()";
|
||||
|
||||
/// <summary>
|
||||
/// Full screen, done on the page itself: the element is pinned over the whole of the phone's page. The browser
|
||||
/// runs without a window of its own, so the real thing was refused or came out the wrong size and shifted to
|
||||
/// one side, and each site's fallback for that came out crooked in its own way.
|
||||
/// </summary>
|
||||
const string Full =
|
||||
"(()=>{let fe=null,was=null,hid=[];const ev=e=>{for(const n of['fullscreenchange','webkitfullscreenchange'])e.dispatchEvent(new Event(n,{bubbles:true}))};" +
|
||||
"const exit=function(){if(!fe)return Promise.resolve();const e=fe;fe=null;for(const[h,v]of hid)h.style.visibility=v;hid=[];if(was)e.setAttribute('style',was);else e.removeAttribute('style');ev(e);return Promise.resolve()};" +
|
||||
"const enter=function(){if(fe===this)return Promise.resolve();if(fe)exit();fe=this;was=this.getAttribute('style');" +
|
||||
"this.style.cssText+=';position:fixed!important;left:0!important;top:0!important;right:auto!important;bottom:auto!important;width:100vw!important;height:100vh!important;" +
|
||||
"max-width:none!important;max-height:none!important;margin:0!important;transform:none!important;z-index:2147483647!important;background:#000!important';" +
|
||||
// whatever else is on the page (a site's own header sits above the player) is hidden while it lasts
|
||||
"for(let n=this;n&&n.parentElement;n=n.parentElement)for(const o of n.parentElement.children)if(o!==n){hid.push([o,o.style.visibility]);o.style.setProperty('visibility','hidden','important')}" +
|
||||
"ev(this);return Promise.resolve()};" +
|
||||
"for(const n of['requestFullscreen','webkitRequestFullscreen','webkitRequestFullScreen'])Element.prototype[n]=enter;" +
|
||||
"HTMLVideoElement.prototype.webkitEnterFullscreen=enter;HTMLVideoElement.prototype.webkitEnterFullScreen=enter;" +
|
||||
"for(const n of['exitFullscreen','webkitExitFullscreen','webkitCancelFullScreen'])Document.prototype[n]=exit;" +
|
||||
"for(const n of['fullscreenElement','webkitFullscreenElement','webkitCurrentFullScreenElement'])Object.defineProperty(Document.prototype,n,{get:()=>fe,configurable:true});" +
|
||||
"for(const n of['fullscreenEnabled','webkitFullscreenEnabled'])Object.defineProperty(Document.prototype,n,{get:()=>true,configurable:true})})()";
|
||||
|
||||
/// <summary>One running browser. A new one is made after a crash, so a late message from the old one can't touch it.</summary>
|
||||
sealed class Link
|
||||
@ -154,9 +174,21 @@ namespace GrassCutter
|
||||
void Metrics()
|
||||
{
|
||||
string turned = _wide ? ",\"screenOrientation\":{\"type\":\"landscapePrimary\",\"angle\":90}" : ",\"screenOrientation\":{\"type\":\"portraitPrimary\",\"angle\":0}";
|
||||
Cmd("Emulation.setDeviceMetricsOverride", $"{{\"width\":{CssW},\"height\":{CssH},\"deviceScaleFactor\":2,\"mobile\":true{turned}}}");
|
||||
Cmd("Emulation.setDeviceMetricsOverride", $"{{\"width\":{CssW},\"height\":{CssH},\"screenWidth\":{CssW},\"screenHeight\":{CssH},\"deviceScaleFactor\":2,\"mobile\":true{turned}}}");
|
||||
Bounds();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The browser's own window the size of the phone's page. A site going full screen fills the window, not the page
|
||||
/// the phone shows, so with the window left at its start-up size the video came out shifted off to one side.
|
||||
/// </summary>
|
||||
void Bounds()
|
||||
{
|
||||
if (_winId > 0) Cmd("Browser.setWindowBounds", $"{{\"windowId\":{_winId},\"bounds\":{{\"width\":{CssW},\"height\":{CssH}}}}}");
|
||||
}
|
||||
|
||||
volatile int _winAsk, _winId;
|
||||
|
||||
// ───────────────────────── fingers ─────────────────────────
|
||||
|
||||
public void Touch(string type, float x, float y)
|
||||
@ -231,7 +263,7 @@ namespace GrassCutter
|
||||
var done = new TaskCompletionSource<string>();
|
||||
if (!Ready) { done.TrySetResult(null); return done.Task; }
|
||||
_wait[id] = done;
|
||||
Send(_link, "{\"id\":" + id + ",\"method\":\"Runtime.evaluate\",\"params\":{\"expression\":" + Str(js) + ",\"awaitPromise\":true}}");
|
||||
Send(_link, "{\"id\":" + id + ",\"method\":\"Runtime.evaluate\",\"params\":{\"expression\":" + Str(js) + ",\"awaitPromise\":true,\"userGesture\":true}}");
|
||||
return done.Task;
|
||||
}
|
||||
|
||||
@ -394,7 +426,7 @@ namespace GrassCutter
|
||||
catch (UnauthorizedAccessException) { await Task.Delay(100); }
|
||||
}
|
||||
string args = "--headless=new --remote-debugging-port=0 --user-data-dir=\"" + _profile + "\" --no-first-run --no-default-browser-check " +
|
||||
"--autoplay-policy=no-user-gesture-required --hide-crash-restore-bubble --disable-sync --disk-cache-size=157286400 --window-size=412,875 " + (_mute ? "--mute-audio " : "") + "about:blank";
|
||||
"--autoplay-policy=no-user-gesture-required --disable-blink-features=AutomationControlled --hide-crash-restore-bubble --disable-sync --disk-cache-size=157286400 --window-size=412,875 " + (_mute ? "--mute-audio " : "") + "about:blank";
|
||||
link.Proc = Process.Start(new ProcessStartInfo(exe, args) { UseShellExecute = false, CreateNoWindow = true });
|
||||
TieToGame(link);
|
||||
|
||||
@ -407,7 +439,7 @@ namespace GrassCutter
|
||||
}
|
||||
if (port == null) throw new TimeoutException("The browser didn't start.");
|
||||
|
||||
string ws, ua;
|
||||
string ws, ua, chrome;
|
||||
using (var http = new HttpClient(new HttpClientHandler { UseProxy = false }))
|
||||
{
|
||||
// the debug server hangs up after each answer, so no reusing the connection
|
||||
@ -423,7 +455,7 @@ namespace GrassCutter
|
||||
foreach (Match old in Regex.Matches(open, "\"id\"\\s*:\\s*\"([^\"]+)\"[^{}]*?\"type\"\\s*:\\s*\"page\""))
|
||||
await http.GetAsync($"http://127.0.0.1:{port}/json/close/{old.Groups[1].Value}");
|
||||
var version = await http.GetStringAsync($"http://127.0.0.1:{port}/json/version");
|
||||
string chrome = Regex.Match(version, "\"Browser\"\\s*:\\s*\"[^/]+/(\\d+)").Groups[1].Value;
|
||||
chrome = Regex.Match(version, "\"Browser\"\\s*:\\s*\"[^/]+/(\\d+)").Groups[1].Value;
|
||||
ua = $"Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/{chrome}.0.0.0 Mobile Safari/537.36";
|
||||
}
|
||||
|
||||
@ -434,10 +466,18 @@ namespace GrassCutter
|
||||
_ = Task.Run(() => Receiver(link));
|
||||
|
||||
Send(link, "Page.enable", "{}");
|
||||
Send(link, "Emulation.setUserAgentOverride", "{\"userAgent\":" + Str(ua) + ",\"platform\":\"Linux armv8l\"}");
|
||||
// the whole of a phone's Chrome, client hints included: with only the agent string swapped, the hints still
|
||||
// said HeadlessChrome on Windows, and YouTube stopped a video a couple of minutes in ("something went wrong")
|
||||
string brands = $"[{{\"brand\":\"Chromium\",\"version\":\"{chrome}\"}},{{\"brand\":\"Google Chrome\",\"version\":\"{chrome}\"}},{{\"brand\":\"Not.A/Brand\",\"version\":\"99\"}}]";
|
||||
string full = $"[{{\"brand\":\"Chromium\",\"version\":\"{chrome}.0.0.0\"}},{{\"brand\":\"Google Chrome\",\"version\":\"{chrome}.0.0.0\"}},{{\"brand\":\"Not.A/Brand\",\"version\":\"99.0.0.0\"}}]";
|
||||
Send(link, "Emulation.setUserAgentOverride", "{\"userAgent\":" + Str(ua) + ",\"platform\":\"Linux armv8l\",\"userAgentMetadata\":{\"brands\":" + brands +
|
||||
",\"fullVersionList\":" + full + ",\"platform\":\"Android\",\"platformVersion\":\"14.0.0\",\"architecture\":\"\",\"model\":\"Pixel 8\",\"mobile\":true}}");
|
||||
Send(link, "Emulation.setTouchEmulationEnabled", "{\"enabled\":true,\"maxTouchPoints\":5}");
|
||||
Send(link, "Browser.setDownloadBehavior", "{\"behavior\":\"deny\"}");
|
||||
Send(link, "Page.addScriptToEvaluateOnNewDocument", "{\"source\":" + Str(Keep) + "}");
|
||||
Send(link, "Page.addScriptToEvaluateOnNewDocument", "{\"source\":" + Str(Keep + ";" + Full) + "}");
|
||||
int win = Interlocked.Increment(ref _id);
|
||||
_winAsk = win;
|
||||
Send(link, "{\"id\":" + win + ",\"method\":\"Browser.getWindowForTarget\",\"params\":{}}");
|
||||
Metrics();
|
||||
if (_shown) Screencast(true);
|
||||
link.Ready = true;
|
||||
@ -504,7 +544,7 @@ namespace GrassCutter
|
||||
[Serializable] class Msg { public int id; public string method; public Params @params; public Outer result; }
|
||||
[Serializable] class Params { public string url, frameId; public FrameInfo frame; }
|
||||
[Serializable] class FrameInfo { public string url; public string parentId; }
|
||||
[Serializable] class Outer { public Inner result; public string errorText; }
|
||||
[Serializable] class Outer { public Inner result; public string errorText; public int windowId; }
|
||||
[Serializable] class Inner { public string value; }
|
||||
|
||||
async Task Receiver(Link link)
|
||||
@ -565,6 +605,7 @@ namespace GrassCutter
|
||||
{
|
||||
if (_wait.TryRemove(m.id, out var done)) done.TrySetResult(m.result?.result?.value);
|
||||
if (m.id == _navId && !string.IsNullOrEmpty(m.result?.errorText)) _navError = m.result.errorText;
|
||||
if (m.id == _winAsk && m.result != null && m.result.windowId > 0) { _winId = m.result.windowId; Bounds(); }
|
||||
}
|
||||
else if (m.method == "Page.frameNavigated")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user