@@ -288,6 +288,8 @@ public IWebBrowserLogger Logger
288288
289289 #endregion
290290
291+ private bool headless ;
292+ private bool hasInitialized ;
291293 private EngineProcess engineProcess ;
292294 private WebBrowserCommunicationsManager communicationsManager ;
293295 private CancellationTokenSource cancellationSource ;
@@ -296,16 +298,33 @@ public IWebBrowserLogger Logger
296298 private NativeArray < byte > textureData ;
297299 internal NativeArray < byte > nextTextureData ;
298300
299- internal WebBrowserClient ( )
301+ /// <summary>
302+ /// Creates a new <see cref="WebBrowserClient"/> instance
303+ /// </summary>
304+ /// <param name="headless">
305+ /// Creates the browser client in headless mode.
306+ /// Headless mode will not create a <see cref="BrowserTexture"/> for you to use
307+ /// </param>
308+ public WebBrowserClient ( bool headless = false )
300309 {
310+ this . headless = headless ;
301311 }
302312
303313 /// <summary>
304- /// Inits the browser client
314+ /// Inits the browser client.
315+ /// In normal operation you do not need to call this method.
305316 /// </summary>
306317 /// <exception cref="FileNotFoundException"></exception>
307- internal void Init ( )
318+ /// <exception cref="InitializationException"></exception>
319+ public void Init ( )
308320 {
321+ //Initialized check
322+ if ( hasInitialized )
323+ throw new InitializationException ( "The browser client has already been initialized!" ) ;
324+
325+ hasInitialized = true ;
326+
327+ //OS support check
309328 if ( ! WebBrowserUtils . IsRunningOnSupportedPlatform ( ) )
310329 {
311330 logger . Warn ( "UWB is not supported on the current runtime platform! Not running." ) ;
@@ -329,14 +348,16 @@ internal void Init()
329348 communicationLayer . IsInUse = true ;
330349
331350 //Setup texture
332- BrowserTexture = new Texture2D ( ( int ) resolution . Width , ( int ) resolution . Height , TextureFormat . BGRA32 , false ,
333- false ) ;
334- WebBrowserUtils . SetAllTextureColorToOne ( BrowserTexture , backgroundColor ) ;
335-
336- resizeLock = new object ( ) ;
337- textureData = BrowserTexture . GetRawTextureData < byte > ( ) ;
338- nextTextureData = new NativeArray < byte > ( textureData . ToArray ( ) , Allocator . Persistent ) ;
339-
351+ if ( ! headless )
352+ {
353+ BrowserTexture = new Texture2D ( ( int ) resolution . Width , ( int ) resolution . Height , TextureFormat . BGRA32 , false ,
354+ false ) ;
355+ WebBrowserUtils . SetAllTextureColorToOne ( BrowserTexture , backgroundColor ) ;
356+ resizeLock = new object ( ) ;
357+ textureData = BrowserTexture . GetRawTextureData < byte > ( ) ;
358+ nextTextureData = new NativeArray < byte > ( textureData . ToArray ( ) , Allocator . Persistent ) ;
359+ }
360+
340361 string browserEngineMainDir = WebBrowserUtils . GetAdditionFilesDirectory ( ) ;
341362
342363 //Start to build our arguments
@@ -412,11 +433,6 @@ internal void Init()
412433 argsBuilder . AppendArgument ( "ignore-ssl-errors-domains" , string . Join ( "," , ignoreSslErrorsDomains ) ) ;
413434 }
414435
415- //Make sure not to include this, its for testing
416- #if UWB_ENGINE_PRJ //Define for backup, cause I am dumb as fuck and gonna accidentally include this in a release build one day
417- //argsBuilder.AppendArgument("start-delay", 2000);
418- #endif
419-
420436 //Disable sandbox
421437 if ( noSandbox )
422438 {
@@ -536,6 +552,10 @@ internal async UniTaskVoid EngineReady()
536552 }
537553 }
538554
555+ //Create pixel data loop in headless mode
556+ if ( headless )
557+ return ;
558+
539559 Thread pixelDataLoopThread = new ( PixelDataLoop )
540560 {
541561 Name = "UWB Pixel Data Loop Thread"
0 commit comments