@@ -1146,15 +1146,43 @@ impl Page {
11461146 self . inner . frame_secondary_execution_context ( frame_id) . await
11471147 }
11481148
1149- /// Evaluates given script in every frame upon creation (before loading
1150- /// frame's scripts)
1149+ /// Evaluates given script in every frame upon creation (before loading frame's scripts).
1150+ ///
1151+ /// This is equivalent to Playwright's `addInitScript()` or Puppeteer's `evaluateOnNewDocument()`.
1152+ /// Useful for modifying the JavaScript environment before page scripts run, such as:
1153+ /// - Hiding automation detection properties
1154+ /// - Injecting polyfills
1155+ /// - Setting up global variables
1156+ ///
1157+ /// # Example
1158+ /// ```
1159+ /// # use chromiumoxide::page::Page;
1160+ /// # async fn example(page: Page) -> Result<(), Box<dyn std::error::Error>> {
1161+ /// // Hide webdriver property for stealth scraping
1162+ /// page.evaluate_on_new_document(r#"
1163+ /// Object.defineProperty(navigator, 'webdriver', {
1164+ /// get: () => undefined
1165+ /// });
1166+ /// "#).await?;
1167+ /// # Ok(())
1168+ /// # }
1169+ /// ```
11511170 pub async fn evaluate_on_new_document (
11521171 & self ,
11531172 script : impl Into < AddScriptToEvaluateOnNewDocumentParams > ,
11541173 ) -> Result < ScriptIdentifier > {
11551174 Ok ( self . execute ( script. into ( ) ) . await ?. result . identifier )
11561175 }
11571176
1177+ /// Alias for `evaluate_on_new_document` - familiar to Playwright users.
1178+ #[ inline]
1179+ pub async fn add_init_script (
1180+ & self ,
1181+ script : impl Into < AddScriptToEvaluateOnNewDocumentParams > ,
1182+ ) -> Result < ScriptIdentifier > {
1183+ self . evaluate_on_new_document ( script) . await
1184+ }
1185+
11581186 /// Set the content of the frame.
11591187 ///
11601188 /// # Example
0 commit comments