From 57eba83cb6d62079adc33b6bcbf35acdd842ef8e Mon Sep 17 00:00:00 2001 From: Luan Date: Wed, 15 Jan 2025 14:23:11 -0300 Subject: [PATCH] chore(examples): Update browser example --- examples/browser/web/src/main.ts | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/examples/browser/web/src/main.ts b/examples/browser/web/src/main.ts index 139098cf..a360e067 100644 --- a/examples/browser/web/src/main.ts +++ b/examples/browser/web/src/main.ts @@ -28,11 +28,6 @@ function fetchFn(input: RequestInfo | URL, init?: RequestInit) { // Now serialize the headers. url.searchParams.set('__headers', JSON.stringify([...headers])); - if (input instanceof Request) { - // @ts-expect-error - x - input.duplex = 'half'; - } - // Copy over the request. const request = new Request( url, @@ -78,25 +73,14 @@ async function getPo(identifier: string): Promise { console.warn('Unable to load VM.'); } - const poToken = await BG.PoToken.generate({ + return await BG.PoToken.generate({ program: challenge.challenge, globalName: challenge.globalName, bgConfig }); - - return poToken; } async function main() { - const oauthCreds = undefined; - // Const oauthCreds = { - // Access_token: 'ya29.abcd', - // Refresh_token: '1//0abcd', - // Scope: 'https://www.googleapis.com/auth/youtube-paid-content https://www.googleapis.com/auth/youtube', - // Token_type: 'Bearer', - // Expiry_date: '2024-08-13T04:41:34.757Z' - // }; - const visitorData = ProtoUtils.encodeVisitorData(Utils.generateRandomString(11), Math.floor(Date.now() / 1000)); const poToken = await getPo(visitorData); @@ -108,9 +92,6 @@ async function main() { cache: new UniversalCache(false) }); - if (oauthCreds) - await yt.session.signIn(oauthCreds); - form.animate({ opacity: [0, 1] }, { duration: 300, easing: 'ease-in-out' }); form.style.display = 'block'; @@ -171,7 +152,7 @@ async function main() { cache: new UniversalCache(false) }); - await yt.session.signIn(oauthCreds); + // await yt.session.signIn(oauthCreds); } } @@ -185,7 +166,7 @@ async function main() { metadata.innerHTML = ''; metadata.innerHTML += `
${info.primary_info?.published.toHTML()}
`; - metadata.innerHTML += `
${info.primary_info?.view_count.toHTML()}
`; + metadata.innerHTML += `
${info.primary_info?.view_count?.short_view_count.toHTML()}
`; metadata.innerHTML += `
${info.basic_info.like_count} likes
`; showUI({ hidePlayer: false }); @@ -200,7 +181,7 @@ async function main() { } if (ui) { - ui.destroy(); + await ui.destroy(); ui = undefined; } @@ -342,7 +323,7 @@ async function main() { const streamProtectionStatus = Protos.StreamProtectionStatus.decode(data); switch (streamProtectionStatus.status) { case 1: - console.info('[StreamProtectionStatus]: Good'); + console.info('[StreamProtectionStatus]: OK'); break; case 2: console.error('[StreamProtectionStatus]: Attestation pending'); @@ -405,4 +386,4 @@ function hideUI() { loader.style.display = 'block'; } -main(); \ No newline at end of file +main().then(r => r).catch(console.error); \ No newline at end of file