@@ -174,6 +174,59 @@ public RouteOptions setTimes(int times) {
174174 return this ;
175175 }
176176 }
177+ class RouteFromHAROptions {
178+ /**
179+ * <ul>
180+ * <li> If set to 'abort' any request not found in the HAR file will be aborted.</li>
181+ * <li> If set to 'fallback' falls through to the next route handler in the handler chain.</li>
182+ * </ul>
183+ *
184+ * <p> Defaults to abort.
185+ */
186+ public HarNotFound notFound ;
187+ /**
188+ * A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the pattern
189+ * will be surved from the HAR file. If not specified, all requests are served from the HAR file.
190+ */
191+ public Object url ;
192+
193+ /**
194+ * <ul>
195+ * <li> If set to 'abort' any request not found in the HAR file will be aborted.</li>
196+ * <li> If set to 'fallback' falls through to the next route handler in the handler chain.</li>
197+ * </ul>
198+ *
199+ * <p> Defaults to abort.
200+ */
201+ public RouteFromHAROptions setNotFound (HarNotFound notFound ) {
202+ this .notFound = notFound ;
203+ return this ;
204+ }
205+ /**
206+ * A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the pattern
207+ * will be surved from the HAR file. If not specified, all requests are served from the HAR file.
208+ */
209+ public RouteFromHAROptions setUrl (String url ) {
210+ this .url = url ;
211+ return this ;
212+ }
213+ /**
214+ * A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the pattern
215+ * will be surved from the HAR file. If not specified, all requests are served from the HAR file.
216+ */
217+ public RouteFromHAROptions setUrl (Pattern url ) {
218+ this .url = url ;
219+ return this ;
220+ }
221+ /**
222+ * A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the pattern
223+ * will be surved from the HAR file. If not specified, all requests are served from the HAR file.
224+ */
225+ public RouteFromHAROptions setUrl (Predicate <String > url ) {
226+ this .url = url ;
227+ return this ;
228+ }
229+ }
177230 class StorageStateOptions {
178231 /**
179232 * The file path to save the storage state to. If {@code path} is a relative path, then it is resolved relative to current
@@ -553,9 +606,9 @@ default void grantPermissions(List<String> permissions) {
553606 * Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
554607 * is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
555608 *
556- * <p> <strong>NOTE:</strong> {@link Page #route Page .route()} will not intercept requests intercepted by Service Worker. See <a
609+ * <p> <strong>NOTE:</strong> {@link BrowserContext #route BrowserContext .route()} will not intercept requests intercepted by Service Worker. See <a
557610 * href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
558- * using request interception. Via {@code await context.addInitScript(() => delete window.navigator.serviceWorker);}
611+ * using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
559612 *
560613 * <p> An example of a naive handler that aborts all image requests:
561614 * <pre>{@code
@@ -605,9 +658,9 @@ default void route(String url, Consumer<Route> handler) {
605658 * Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
606659 * is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
607660 *
608- * <p> <strong>NOTE:</strong> {@link Page #route Page .route()} will not intercept requests intercepted by Service Worker. See <a
661+ * <p> <strong>NOTE:</strong> {@link BrowserContext #route BrowserContext .route()} will not intercept requests intercepted by Service Worker. See <a
609662 * href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
610- * using request interception. Via {@code await context.addInitScript(() => delete window.navigator.serviceWorker);}
663+ * using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
611664 *
612665 * <p> An example of a naive handler that aborts all image requests:
613666 * <pre>{@code
@@ -655,9 +708,9 @@ default void route(String url, Consumer<Route> handler) {
655708 * Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
656709 * is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
657710 *
658- * <p> <strong>NOTE:</strong> {@link Page #route Page .route()} will not intercept requests intercepted by Service Worker. See <a
711+ * <p> <strong>NOTE:</strong> {@link BrowserContext #route BrowserContext .route()} will not intercept requests intercepted by Service Worker. See <a
659712 * href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
660- * using request interception. Via {@code await context.addInitScript(() => delete window.navigator.serviceWorker);}
713+ * using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
661714 *
662715 * <p> An example of a naive handler that aborts all image requests:
663716 * <pre>{@code
@@ -707,9 +760,9 @@ default void route(Pattern url, Consumer<Route> handler) {
707760 * Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
708761 * is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
709762 *
710- * <p> <strong>NOTE:</strong> {@link Page #route Page .route()} will not intercept requests intercepted by Service Worker. See <a
763+ * <p> <strong>NOTE:</strong> {@link BrowserContext #route BrowserContext .route()} will not intercept requests intercepted by Service Worker. See <a
711764 * href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
712- * using request interception. Via {@code await context.addInitScript(() => delete window.navigator.serviceWorker);}
765+ * using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
713766 *
714767 * <p> An example of a naive handler that aborts all image requests:
715768 * <pre>{@code
@@ -757,9 +810,9 @@ default void route(Pattern url, Consumer<Route> handler) {
757810 * Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
758811 * is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
759812 *
760- * <p> <strong>NOTE:</strong> {@link Page #route Page .route()} will not intercept requests intercepted by Service Worker. See <a
813+ * <p> <strong>NOTE:</strong> {@link BrowserContext #route BrowserContext .route()} will not intercept requests intercepted by Service Worker. See <a
761814 * href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
762- * using request interception. Via {@code await context.addInitScript(() => delete window.navigator.serviceWorker);}
815+ * using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
763816 *
764817 * <p> An example of a naive handler that aborts all image requests:
765818 * <pre>{@code
@@ -809,9 +862,9 @@ default void route(Predicate<String> url, Consumer<Route> handler) {
809862 * Routing provides the capability to modify network requests that are made by any page in the browser context. Once route
810863 * is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
811864 *
812- * <p> <strong>NOTE:</strong> {@link Page #route Page .route()} will not intercept requests intercepted by Service Worker. See <a
865+ * <p> <strong>NOTE:</strong> {@link BrowserContext #route BrowserContext .route()} will not intercept requests intercepted by Service Worker. See <a
813866 * href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
814- * using request interception. Via {@code await context.addInitScript(() => delete window.navigator.serviceWorker);}
867+ * using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
815868 *
816869 * <p> An example of a naive handler that aborts all image requests:
817870 * <pre>{@code
@@ -855,6 +908,32 @@ default void route(Predicate<String> url, Consumer<Route> handler) {
855908 * @param handler handler function to route the request.
856909 */
857910 void route (Predicate <String > url , Consumer <Route > handler , RouteOptions options );
911+ /**
912+ * If specified the network requests that are made in the context will be served from the HAR file. Read more about <a
913+ * href="https://playwright.dev/java/docs/network#replaying-from-har">Replaying from HAR</a>.
914+ *
915+ * <p> Playwright will not serve requests intercepted by Service Worker from the HAR file. See <a
916+ * href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
917+ * using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
918+ *
919+ * @param har Path to a <a href="http://www.softwareishard.com/blog/har-12-spec">HAR</a> file with prerecorded network data. If {@code path}
920+ * is a relative path, then it is resolved relative to the current working directory.
921+ */
922+ default void routeFromHAR (Path har ) {
923+ routeFromHAR (har , null );
924+ }
925+ /**
926+ * If specified the network requests that are made in the context will be served from the HAR file. Read more about <a
927+ * href="https://playwright.dev/java/docs/network#replaying-from-har">Replaying from HAR</a>.
928+ *
929+ * <p> Playwright will not serve requests intercepted by Service Worker from the HAR file. See <a
930+ * href="https://github.com/microsoft/playwright/issues/1090">this</a> issue. We recommend disabling Service Workers when
931+ * using request interception by setting {@code Browser.newContext.serviceWorkers} to {@code "block"}.
932+ *
933+ * @param har Path to a <a href="http://www.softwareishard.com/blog/har-12-spec">HAR</a> file with prerecorded network data. If {@code path}
934+ * is a relative path, then it is resolved relative to the current working directory.
935+ */
936+ void routeFromHAR (Path har , RouteFromHAROptions options );
858937 /**
859938 * This setting will change the default maximum navigation time for the following methods and related shortcuts:
860939 * <ul>
0 commit comments