@@ -3,7 +3,6 @@ import { Col, Grid, IconButton, Loader, Panel, CustomProvider } from 'rsuite'
33import PlayIcon from '@rsuite/icons/PlayOutline' ;
44
55import { ExecutionResponse , runCode , trackEvent } from '../../utils'
6- import { waitForTurnstileToken } from '../../turnstile'
76import RightPanel from '../RightPanel'
87import Header from '../Header'
98import Editor from '../Editor'
@@ -22,39 +21,52 @@ const App: React.FunctionComponent = () => {
2221 const handleExecutionRef = useRef < ( ) => Promise < void > > ( undefined )
2322 const [ darkMode ] = useDarkMode ( )
2423 const turnstileRef = useRef < HTMLDivElement > ( null )
25- const skipTurnstile = Boolean ( window . __TRY_PLAYWRIGHT__ ?. skipTurnstile )
2624
2725 const handleExecution = async ( ) : Promise < void > => {
2826 setLoading ( true )
2927 setResponse ( null )
3028
3129 trackEvent ( )
32- const turnstileToken = skipTurnstile
33- ? ''
34- : await waitForTurnstileToken ( {
35- turnstile : window . turnstile ,
36- container : turnstileRef . current ,
37- sitekey : VITE_TURNSTILE_SITEKEY ,
38- } )
30+ const started = Date . now ( )
31+ console . info ( '[try-playwright] run: before-turnstile' , {
32+ hasExecute : typeof ( window as any ) . turnstile ?. execute ,
33+ elapsedMs : 0 ,
34+ } )
35+ const turnstileToken = await new Promise < string > ( ( resolve ) => {
36+ try {
37+ ( window as any ) . turnstile . reset ( ) ;
38+ } catch ( error ) { }
39+ ( window as any ) . turnstile . execute ( turnstileRef . current , {
40+ sitekey : VITE_TURNSTILE_SITEKEY ,
41+ callback : ( token : string ) => {
42+ console . info ( '[try-playwright] run: turnstile-callback' , {
43+ elapsedMs : Date . now ( ) - started ,
44+ tokenLength : token ? token . length : 0 ,
45+ } )
46+ resolve ( token )
47+ } ,
48+ 'error-callback' : ( ) => {
49+ console . info ( '[try-playwright] run: turnstile-error-callback' , {
50+ elapsedMs : Date . now ( ) - started ,
51+ } )
52+ resolve ( '' )
53+ } ,
54+ } ) ;
55+ } ) ;
3956 const codeToRun = getCode ( )
40- try {
41- setResponse ( await runCode ( codeToRun , codeLanguage , turnstileToken ) )
42- } finally {
43- setLoading ( false )
44- onChangeRightPanelMode ( false )
45- }
57+ console . info ( '[try-playwright] run: posting' , {
58+ elapsedMs : Date . now ( ) - started ,
59+ codeLength : codeToRun . length ,
60+ } )
61+ setResponse ( await runCode ( codeToRun , codeLanguage , turnstileToken ) )
62+ setLoading ( false )
63+ onChangeRightPanelMode ( false )
4664 }
4765 handleExecutionRef . current = handleExecution
4866
4967 return (
5068 < CustomProvider theme = { darkMode ? 'dark' : 'light' } >
51- { ! skipTurnstile && (
52- < div
53- ref = { turnstileRef }
54- aria-hidden = "true"
55- style = { { position : 'fixed' , left : 0 , bottom : 0 , width : 300 , height : 65 , opacity : 0.01 , pointerEvents : 'none' , overflow : 'hidden' } }
56- />
57- ) }
69+ < div ref = { turnstileRef } style = { { display : 'none' } } />
5870 < Header />
5971 < Grid fluid className = { styles . grid } >
6072 < Col span = { { xs : 24 , md : 12 } } >
0 commit comments