Skip to content

v4.0.0

Choose a tag to compare

@1natsu172 1natsu172 released this 28 Aug 06:29
· 167 commits to master since this release

Major update 🚀

New Features

detector option for customized element detector

The option name is detector.optional

This is useful for use cases like wanting to fulfill after checking the state of an element. The return value type is explicitly defined, and when the condition is not fulfilled, it must return { isDetected: false }. Also, the resolved value of waitElement will be the returned result.

const waitPenguin = await waitElement("#animal", {
	detector: (element) => {
		return element?.textContent === "Penguin"
			? { isDetected: true, result: element }
			: { isDetected: false };
	},
});

AbortController is supported

The option name is signal.optional

You can now abort operations in the same way as the native fetch API.

const ac = new AbortController();

const checkElement = waitElement("#find", { signal: ac.signal });

await delay(300); // In fact, there will be some kind of process...

ac.abort("I feel like interrupting");

Performance optimization for concurrent processing

The option name is unifyProcess.optional

This option is enabled(true) by default.

// all waitElement internal process unified
await Promise.all([
	waitElement(".unify", {
		unifyProcess: true,
	}),
	waitElement(".unify", {
		unifyProcess: true,
	}),
	waitElement(".unify", {
		unifyProcess: true,
	}),
]);

About the all options

Note

See TS definition for detailed options information.

BREAKING CHANGE

Warning

There are some breaking changes!

waitDisappearElement has been removed

To replicate waitDisappearElement in v4, use the following approach.

BEFORE

import { waitDisappearElement } from "@1natsu/wait-element";

await waitDisappearElement('.will-disappear');

AFTER

import { isNotExist } from "@1natsu/wait-element/detectors";

await waitElement(".will-disappear", { detector: isNotExist });

Timeout API has changed

The timeout option has been removed. Please use AbortSignal.timeout() instead.

BEFORE

await waitElement('.late-comming', { timeout: 5000 });

AFTER

await waitElement('.late-comming', { signal: AbortSignal.timeout(5000) });

Cancel API has changed

The cancelable API has been removed. Please use AbortController instead.

BEFORE

let el;
try {
  el = waitElement('.cancelable');
  if (!isCondition) el.cancel();
} catch {
  // some handling...
}

AFTER

const ac = new AbortController();
let el;
try {
  el = waitElement(".aborted", {
    signal: ac.signal,
  });
  if (!isCondition) ac.abort("abort!");
} catch (error) {
  // some handling...
}

Concurrent processing is now enabled by default

If you want to use concurrent processing as in v3, set unifyProcess to false.

await waitElement(".please-no-unify", {
  unifyProcess: false,
});

Changed logs

Full Changelog: v3.0.0...v4.0.0