Class: NativeDialogHandler
Observes and optionally answers native browser dialogs.
Example
const handler = new NativeDialogHandler({ page });
handler.observe();
Constructors
Constructor
new NativeDialogHandler(
options):NativeDialogHandler
Parameters
options
NativeDialogHandlerOptions
Returns
NativeDialogHandler
Accessors
records
Get Signature
get records(): readonly
NativeDialogRecord[]
Every dialog seen so far, in order.
Returns
readonly NativeDialogRecord[]
Methods
dispose()
dispose():
void
Removes every listener this handler attached.
Returns
void
Remarks
Removing the dialog listener hands dialogs back to Playwright, which
resumes auto-dismissing them. Safe to call when nothing was registered.
Example
handler.dispose();
observe()
observe():
void
Starts recording dialogs without changing behaviour.
Returns
void
Remarks
Attaches only dialogclosed, never dialog, so Playwright keeps
auto-dismissing exactly as it would without Praman. Safe to call
unconditionally; calling it twice is a no-op.
Degrades to no diagnostics below Playwright MIN_DIALOG_CLOSED_VERSION and logs that it did. It does not throw: there is no floor equivalent for watching a dialog without taking responsibility for it, and observation is additive, so silence is the honest degrade rather than denying the caller a working test.
Example
handler.observe();
register()
register(
rule):void
Opts into answering dialogs according to a rule.
Parameters
rule
The policy to add.
Returns
void
Remarks
The first call attaches the single dialog listener. From that moment
Playwright stops auto-dismissing, so this class answers every dialog:
a type no rule covers, or a rule that has hit its times cap, is
dismissed and logged at warn rather than left to freeze the page.
Throws
PramanError with ERR_CONFIG_INVALID for an empty types list or
a duplicate rule name.
Example
handler.register({ name: 'discard', types: ['beforeunload'], action: 'accept' });
registerAll()
registerAll(
rules):void
Registers several rules in order.
Parameters
rules
readonly NativeDialogRule[]
The policies to add.
Returns
void
Example
handler.registerAll([{ name: 'a', types: ['alert'], action: 'dismiss' }]);