Files
grass-cutters/Assets/Scripts/Core/DemoBot.Tube.cs
NiemandKG 77f533e390 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>
2026-11-17 16:38:00 +06:00

78 lines
5.0 KiB
C#

using System.Collections;
using UnityEngine;
namespace GrassCutter
{
public partial class DemoBot
{
/// <summary>
/// -demoyt: a long YouTube video on the phone for well over the couple of minutes it used to stop at, what the page
/// thinks it runs in, the video full screen with the phone on its side, and the tool belt out of the way of the phone.
/// </summary>
IEnumerator TubeDemo()
{
TeamState.DeleteSave();
yield return new WaitForSeconds(2f);
NetSession.Instance.HostLocal();
while (!Me || !Ts) yield return null;
yield return new WaitForSeconds(2f);
var at = new Vector3(-16f, Soil + 0.1f, 14f);
Me.Teleport(at);
Me.LookAt(at + new Vector3(-6f, 1.4f, 9f));
yield return new WaitForSeconds(0.8f);
var phone = Phone.I;
phone.Show(PhoneMode.Side);
yield return new WaitForSeconds(0.6f);
phone.Show(PhoneMode.Up);
yield return new WaitForSeconds(0.6f);
var scr = phone.Screen;
var web = scr.Web;
scr.Open("https://m.youtube.com/watch?v=aqz-KE-bpKQ");
yield return Until(() => web.Url != null && web.Url.Contains("watch"), 30f);
yield return new WaitForSeconds(4f);
yield return Ask(web, "String(navigator.webdriver)+' '+(navigator.userAgentData?navigator.userAgentData.brands.map(b=>b.brand).join('/')+' '+navigator.userAgentData.platform+' mobile '+navigator.userAgentData.mobile:'no hints')");
Log($"the page sees: webdriver {_said}");
yield return Ask(web, "(()=>{const v=document.querySelector('video');if(!v)return 'no video';v.play().catch(()=>{});return 'playing'})()");
BotCapture.From = null;
yield return Shot("yt_1_up");
const string state = "(()=>{const v=document.querySelector('video');const e=document.querySelector('.ytp-error,ytm-player-error-message-renderer,.player-error,.ytp-error-content');" +
"return (v?Math.round(v.currentTime)+' s, paused '+v.paused:'no video')+(e&&e.offsetParent?' ERROR '+e.innerText.slice(0,90).replace(/\\s+/g,' '):'')})()";
for (int i = 1; i <= (CommandLine.Has("-demoytlong") ? 10 : 1); i++)
{
yield return new WaitForSecondsRealtime(20f);
yield return Ask(web, state);
Log($"after {i * 20} s: {_said}");
if (i == 5) yield return Shot("yt_2_100s");
}
yield return Shot("yt_3_200s");
// on its side and full screen: the video must fill the page, square on
scr.Turn();
yield return new WaitForSeconds(1.5f);
yield return Ask(web, "(()=>{const p=document.querySelector('.html5-video-player')||document.querySelector('video');if(!p)return Promise.resolve('nothing to fill');" +
"return p.requestFullscreen().then(()=>new Promise(r=>setTimeout(r,800))).then(()=>{const b=document.fullscreenElement.getBoundingClientRect();" +
"return 'full screen at '+Math.round(b.x)+','+Math.round(b.y)+' size '+Math.round(b.width)+'x'+Math.round(b.height)+', page '+innerWidth+'x'+innerHeight+', scrolled '+scrollY}).catch(e=>'refused: '+e.message)})()");
Log($"wide, {_said} (phone css {web.CssW}x{web.CssH})");
yield return Shot("yt_4_full");
yield return Ask(web, state);
Log($"full screen: {_said}");
// a page of our own that goes full screen on a real tap, the way a site's own button does
scr.Open("data:text/html,<!doctype html><meta name=viewport content='width=device-width,initial-scale=1'><body style='margin:0;height:3000px;background:%23246'>" +
"<div id=b style='position:absolute;left:0;top:600px;width:100%25;height:300px;background:%23e33;font:40px sans-serif;color:white'>go full</div>" +
"<script>scrollTo(0,500);b.addEventListener('click',()=>b.requestFullscreen().catch(e=>b.dataset.e=e.message))</script>");
yield return Until(() => web.Url != null && web.Url.StartsWith("data:"), 15f);
yield return new WaitForSeconds(1.5f);
var tap = scr.PageAt(0.5f, 0.5f);
scr.Pointer(tap, true, true, false);
yield return null;
scr.Pointer(tap, false, false, true);
yield return new WaitForSeconds(1.5f);
yield return Ask(web, "(()=>{const f=document.fullscreenElement;if(!f)return 'not full screen '+(b.dataset.e||'');const r=f.getBoundingClientRect();return 'at '+Math.round(r.x)+','+Math.round(r.y)+' size '+Math.round(r.width)+'x'+Math.round(r.height)+', page '+innerWidth+'x'+innerHeight})()");
Log($"full screen by a tap: {_said} (phone css {web.CssW}x{web.CssH})");
yield return Shot("yt_5_tapfull");
Log("yt done");
Application.Quit();
}
}
}