Move defer statement to ensure browser closure occurs only after assigning the browser to the context. This prevents potential issues of premature resource release.