ReadonlyaddAdds a script which would be evaluated in one of the following scenarios:
ReadonlyaddAdds a <script> tag into the page with the desired url or content.
ReadonlyaddAdds a <link rel="stylesheet"> tag into the page with the desired url or a <style type="text/css"> tag with the content.
ReadonlybringBrings page to front (activates tab).
ReadonlyclockAccess the clock.
ReadonlycloseCloses the page.
ReadonlyconsoleReturns all messages that have been logged to the console.
ReadonlycontentReturns the full HTML contents of the page, including the doctype.
ReadonlycontextGet the browser context that the page belongs to.
ReadonlydragDrags a source element to a target element and drops it.
ReadonlyemulateThis method changes the CSS media type through the media argument, and/or the 'prefers-colors-scheme' media feature, using the colorScheme argument.
ReadonlyevaluateEvaluates a function in the context of the page.
ReadonlyexposeIdentical to exposeFunction but meant to be used with a static Effect.
This is useful when the exposed function does not need any arguments and just
runs a pre-defined effect in the application context.
import { Console, Effect } from "effect";
import { PlaywrightBrowser } from "effect-playwright/browser";
const program = Effect.gen(function* () {
const browser = yield* PlaywrightBrowser;
const page = yield* browser.newPage();
yield* page.exposeEffect("ping", Console.log("pong"));
yield* page.evaluate(async () => {
// @ts-expect-error
await window.ping();
});
});
ReadonlyexposeAdds a function called name on the window object of every frame in this page.
The provided function must return an Effect which will be executed using the
current runtime when the function is called from the browser context.
If you don't require your function to have args you can use exposeEffect instead.
import { Console, Effect } from "effect";
import { PlaywrightBrowser } from "effect-playwright/browser";
const program = Effect.gen(function* () {
const browser = yield* PlaywrightBrowser;
const page = yield* browser.newPage();
// Expose an Effect-based function to the browser
yield* page.exposeFunction("logMessage", (message: string) =>
Console.log(`Message from browser: ${message}`),
);
yield* page.evaluate(() => {
// Call the exposed function from the browser context
// @ts-expect-error
return window.logMessage("Hello from the other side!");
});
});
import { Context, Effect } from "effect";
import { PlaywrightBrowser } from "effect-playwright/browser";
// A custom Database service used in your Effect application
class Database extends Context.Tag("Database")<
Database,
{ readonly insertProduct: (name: string, price: number) => Effect.Effect<void> }
>() {}
const program = Effect.gen(function* () {
const browser = yield* PlaywrightBrowser;
const page = yield* browser.newPage();
// Expose a function that seamlessly accesses Effect Context using Effect.fn
yield* page.exposeFunction(
"saveProduct",
Effect.fn(function* (name: string, price: number) {
const db = yield* Database;
yield* db.insertProduct(name, price);
}),
);
yield* page.evaluate(async () => {
// Extract data from the page and save it
const items = document.querySelectorAll(".product");
for (const item of items) {
const name = item.querySelector(".name")?.textContent || "Unknown";
const price = Number(item.querySelector(".price")?.textContent || 0);
// Call the Effect function directly from the browser
// @ts-expect-error
await window.saveProduct(name, price);
}
});
});
ReadonlyframeReturns a frame matching the specified criteria.
ReadonlyframesReturns all frames attached to the page.
ReadonlygetReturns a locator that matches the given alt text.
ReadonlygetReturns a locator that matches the given label.
ReadonlygetReturns a locator that matches the given placeholder.
ReadonlygetReturns a locator that matches the given role.
ReadonlygetReturns a locator that matches the given test id.
ReadonlygetReturns a locator that matches the given text.
ReadonlygetReturns a locator that matches the given title.
ReadonlygoNavigate to the previous page in history.
ReadonlygoNavigate to the next page in history.
ReadonlygotoNavigates the page to the given URL.
ReadonlyisIndicates that the page has been closed.
ReadonlykeyboardAccess the keyboard.
ReadonlylocatorReturns a locator for the given selector.
NOTE: This method will cause a defect if options.has or options.hasNot are provided and belong to a different frame.
ReadonlymainThe page's main frame. Page is guaranteed to have a main frame which persists during navigations.
ReadonlymouseAccess the mouse.
ReadonlyopenerReturns the opener for popup pages and Option.none for others.
If the opener has been closed already, returns Option.none.
ReadonlypageReturns all errors that have been thrown in the page.
ReadonlypausePauses the script execution.
ReadonlypdfReturns the PDF buffer.
page.pdf() generates a pdf of the page with print css media. To generate a pdf with screen media, call
PlaywrightPageService.emulateMedia before calling page.pdf().
ReadonlyreloadReloads the page.
ReadonlyrequestRequest the page to perform garbage collection. Note that there is no guarantee that all unreachable objects will be collected.
ReadonlyscreenshotCaptures a screenshot of the page.
ReadonlysetThis method internally calls document.write(), inheriting all its specific characteristics and behaviors.
ReadonlysetThis setting will change the default maximum navigation time for the following methods:
ReadonlysetThis setting will change the default maximum time for all the methods accepting timeout option.
ReadonlysetThe extra HTTP headers will be sent with every request the page initiates.
ReadonlysetSets the viewport size for the page.
ReadonlytitleReturns the page title.
ReadonlytouchscreenAccess the touchscreen.
ReadonlyurlReturns the current URL of the page.
ReadonlyuseA generic utility to execute any promise-based method on the underlying Playwright Page.
Can be used to access any Page functionality not directly exposed by this service.
ReadonlyviewportReturns the viewport size.
ReadonlywaitWaits for the page to reach the given load state.
NOTE: Most of the time, this method is not needed because Playwright auto-waits before every action.
ReadonlywaitWaits for the page to navigate to the given URL.
ReadonlyworkersReturns all workers.
ReadonlyeventCreates a stream of the given event from the page.
ReadonlyclickClicks an element matching the given selector.
Use PlaywrightPageService.locator to create a locator and then call click on it instead.
Since
0.1.0