From 5904bb912480114fe87827d1b05e4bca5758bf30 Mon Sep 17 00:00:00 2001 From: lino-levan <11367844+lino-levan@users.noreply.github.com> Date: Tue, 12 Sep 2023 16:19:01 +1200 Subject: [PATCH] feat: file chooser api --- bindings/_tools/generate/getProtocol.ts | 2 +- deno.lock | 138 +++++++++--------------- docs/pages/guides/navigation.md | 2 +- docs/pages/showcase.tsx | 4 +- examples/navigation.ts | 2 +- src/browser.ts | 2 +- src/cache.ts | 4 +- src/dialog.ts | 27 ++--- src/elementHandle.ts | 2 +- src/fileChooser.ts | 35 ++++++ src/page.ts | 39 ++++++- src/util.ts | 4 +- tests/dialog_test.ts | 56 +++++++++- tests/evaluate_test.ts | 4 +- tests/extract_test.ts | 2 +- tests/stealth_test.ts | 2 +- tests/wait_test.ts | 2 +- 17 files changed, 203 insertions(+), 124 deletions(-) create mode 100644 src/fileChooser.ts diff --git a/bindings/_tools/generate/getProtocol.ts b/bindings/_tools/generate/getProtocol.ts index 10a0c98..59b6d00 100644 --- a/bindings/_tools/generate/getProtocol.ts +++ b/bindings/_tools/generate/getProtocol.ts @@ -1,4 +1,4 @@ -import { existsSync } from "https://deno.land/std@0.198.0/fs/exists.ts"; +import { existsSync } from "https://deno.land/std@0.201.0/fs/exists.ts"; import { getBinary } from "../../../src/cache.ts"; export interface JSDocable { diff --git a/deno.lock b/deno.lock index 2716288..deb7062 100644 --- a/deno.lock +++ b/deno.lock @@ -1,92 +1,56 @@ { "version": "2", "remote": { - "https://deno.land/std@0.198.0/_util/diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea", - "https://deno.land/std@0.198.0/_util/os.ts": "d932f56d41e4f6a6093d56044e29ce637f8dcc43c5a90af43504a889cf1775e3", - "https://deno.land/std@0.198.0/assert/_constants.ts": "8a9da298c26750b28b326b297316cdde860bc237533b07e1337c021379e6b2a9", - "https://deno.land/std@0.198.0/assert/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7", - "https://deno.land/std@0.198.0/assert/assert.ts": "9a97dad6d98c238938e7540736b826440ad8c1c1e54430ca4c4e623e585607ee", - "https://deno.land/std@0.198.0/assert/assert_almost_equals.ts": "e15ca1f34d0d5e0afae63b3f5d975cbd18335a132e42b0c747d282f62ad2cd6c", - "https://deno.land/std@0.198.0/assert/assert_array_includes.ts": "6856d7f2c3544bc6e62fb4646dfefa3d1df5ff14744d1bca19f0cbaf3b0d66c9", - "https://deno.land/std@0.198.0/assert/assert_equals.ts": "a0ee60574e437bcab2dcb79af9d48dc88845f8fd559468d9c21b15fd638ef943", - "https://deno.land/std@0.198.0/assert/assert_exists.ts": "407cb6b9fb23a835cd8d5ad804e2e2edbbbf3870e322d53f79e1c7a512e2efd7", - "https://deno.land/std@0.198.0/assert/assert_false.ts": "a9962749f4bf5844e3fa494257f1de73d69e4fe0e82c34d0099287552163a2dc", - "https://deno.land/std@0.198.0/assert/assert_instance_of.ts": "09fd297352a5b5bbb16da2b5e1a0d8c6c44da5447772648622dcc7df7af1ddb8", - "https://deno.land/std@0.198.0/assert/assert_is_error.ts": "b4eae4e5d182272efc172bf28e2e30b86bb1650cd88aea059e5d2586d4160fb9", - "https://deno.land/std@0.198.0/assert/assert_match.ts": "c4083f80600bc190309903c95e397a7c9257ff8b5ae5c7ef91e834704e672e9b", - "https://deno.land/std@0.198.0/assert/assert_not_equals.ts": "9f1acab95bd1f5fc9a1b17b8027d894509a745d91bac1718fdab51dc76831754", - "https://deno.land/std@0.198.0/assert/assert_not_instance_of.ts": "0c14d3dfd9ab7a5276ed8ed0b18c703d79a3d106102077ec437bfe7ed912bd22", - "https://deno.land/std@0.198.0/assert/assert_not_match.ts": "3796a5b0c57a1ce6c1c57883dd4286be13a26f715ea662318ab43a8491a13ab0", - "https://deno.land/std@0.198.0/assert/assert_not_strict_equals.ts": "ca6c6d645e95fbc873d25320efeb8c4c6089a9a5e09f92d7c1c4b6e935c2a6ad", - "https://deno.land/std@0.198.0/assert/assert_object_match.ts": "d8fc2867cfd92eeacf9cea621e10336b666de1874a6767b5ec48988838370b54", - "https://deno.land/std@0.198.0/assert/assert_rejects.ts": "45c59724de2701e3b1f67c391d6c71c392363635aad3f68a1b3408f9efca0057", - "https://deno.land/std@0.198.0/assert/assert_strict_equals.ts": "5cf29b38b3f8dece95287325723272aa04e04dbf158d886d662fa594fddc9ed3", - "https://deno.land/std@0.198.0/assert/assert_string_includes.ts": "b821d39ebf5cb0200a348863c86d8c4c4b398e02012ce74ad15666fc4b631b0c", - "https://deno.land/std@0.198.0/assert/assert_throws.ts": "63784e951475cb7bdfd59878cd25a0931e18f6dc32a6077c454b2cd94f4f4bcd", - "https://deno.land/std@0.198.0/assert/assertion_error.ts": "4d0bde9b374dfbcbe8ac23f54f567b77024fb67dbb1906a852d67fe050d42f56", - "https://deno.land/std@0.198.0/assert/equal.ts": "9f1a46d5993966d2596c44e5858eec821859b45f783a5ee2f7a695dfc12d8ece", - "https://deno.land/std@0.198.0/assert/fail.ts": "c36353d7ae6e1f7933d45f8ea51e358c8c4b67d7e7502028598fe1fea062e278", - "https://deno.land/std@0.198.0/assert/mod.ts": "08d55a652c22c5da0215054b21085cec25a5da47ce4a6f9de7d9ad36df35bdee", - "https://deno.land/std@0.198.0/assert/unimplemented.ts": "d56fbeecb1f108331a380f72e3e010a1f161baa6956fd0f7cf3e095ae1a4c75a", - "https://deno.land/std@0.198.0/assert/unreachable.ts": "4600dc0baf7d9c15a7f7d234f00c23bca8f3eba8b140286aaca7aa998cf9a536", - "https://deno.land/std@0.198.0/async/deadline.ts": "58f72a3cc0fcb731b2cc055ba046f4b5be3349ff6bf98f2e793c3b969354aab2", - "https://deno.land/std@0.198.0/async/delay.ts": "a6142eb44cdd856b645086af2b811b1fcce08ec06bb7d50969e6a872ee9b8659", - "https://deno.land/std@0.198.0/async/retry.ts": "296fb9c323e1325a69bee14ba947e7da7409a8dd9dd646d70cb51ea0d301f24e", - "https://deno.land/std@0.198.0/fmt/colors.ts": "a7eecffdf3d1d54db890723b303847b6e0a1ab4b528ba6958b8f2e754cf1b3bc", - "https://deno.land/std@0.198.0/fs/_util.ts": "fbf57dcdc9f7bc8128d60301eece608246971a7836a3bb1e78da75314f08b978", - "https://deno.land/std@0.198.0/fs/copy.ts": "b4f7fe87190d7b310c88a2d9ff845210c0a2b7b0a094ec509747359023beb7d6", - "https://deno.land/std@0.198.0/fs/empty_dir.ts": "c3d2da4c7352fab1cf144a1ecfef58090769e8af633678e0f3fabaef98594688", - "https://deno.land/std@0.198.0/fs/ensure_dir.ts": "dc64c4c75c64721d4e3fb681f1382f803ff3d2868f08563ff923fdd20d071c40", - "https://deno.land/std@0.198.0/fs/ensure_file.ts": "c38602670bfaf259d86ca824a94e6cb9e5eb73757fefa4ebf43a90dd017d53d9", - "https://deno.land/std@0.198.0/fs/ensure_link.ts": "c0f5b2f0ec094ed52b9128eccb1ee23362a617457aa0f699b145d4883f5b2fb4", - "https://deno.land/std@0.198.0/fs/ensure_symlink.ts": "5006ab2f458159c56d689b53b1e48d57e05eeb1eaf64e677f7f76a30bc4fdba1", - "https://deno.land/std@0.198.0/fs/eol.ts": "f1f2eb348a750c34500741987b21d65607f352cf7205f48f4319d417fff42842", - "https://deno.land/std@0.198.0/fs/exists.ts": "29c26bca8584a22876be7cb8844f1b6c8fc35e9af514576b78f5c6884d7ed02d", - "https://deno.land/std@0.198.0/fs/expand_glob.ts": "3e427436f4b3768727bd7de84169f10db75fe50b32e6dde567b8ae558a8d857a", - "https://deno.land/std@0.198.0/fs/mod.ts": "bc3d0acd488cc7b42627044caf47d72019846d459279544e1934418955ba4898", - "https://deno.land/std@0.198.0/fs/move.ts": "b4f8f46730b40c32ea3c0bc8eb0fd0e8139249a698883c7b3756424cf19785c9", - "https://deno.land/std@0.198.0/fs/walk.ts": "21a3cc5ff39c38acc93575213f54d5f1d44c5c6614ed97603d171eb0bf56a565", - "https://deno.land/std@0.198.0/path/_basename.ts": "057d420c9049821f983f784fd87fa73ac471901fb628920b67972b0f44319343", - "https://deno.land/std@0.198.0/path/_constants.ts": "e49961f6f4f48039c0dfed3c3f93e963ca3d92791c9d478ac5b43183413136e0", - "https://deno.land/std@0.198.0/path/_dirname.ts": "355e297236b2218600aee7a5301b937204c62e12da9db4b0b044993d9e658395", - "https://deno.land/std@0.198.0/path/_extname.ts": "eaaa5aae1acf1f03254d681bd6a8ce42a9cb5b7ff2213a9d4740e8ab31283664", - "https://deno.land/std@0.198.0/path/_format.ts": "4a99270d6810f082e614309164fad75d6f1a483b68eed97c830a506cc589f8b4", - "https://deno.land/std@0.198.0/path/_from_file_url.ts": "7e4e5626089785adddb061f1b9f4932d6b21c7df778e7449531a11e32048245c", - "https://deno.land/std@0.198.0/path/_interface.ts": "6471159dfbbc357e03882c2266d21ef9afdb1e4aa771b0545e90db58a0ba314b", - "https://deno.land/std@0.198.0/path/_is_absolute.ts": "05dac10b5e93c63198b92e3687baa2be178df5321c527dc555266c0f4f51558c", - "https://deno.land/std@0.198.0/path/_join.ts": "fd78555bc34d5f188918fc7018dfe8fe2df5bbad94a3b30a433666c03934d77f", - "https://deno.land/std@0.198.0/path/_normalize.ts": "a19ec8706b2707f9dd974662a5cd89fad438e62ab1857e08b314a8eb49a34d81", - "https://deno.land/std@0.198.0/path/_parse.ts": "0f9b0ff43682dd9964eb1c4398610c4e165d8db9d3ac9d594220217adf480cfa", - "https://deno.land/std@0.198.0/path/_relative.ts": "27bdeffb5311a47d85be26d37ad1969979359f7636c5cd9fcf05dcd0d5099dc5", - "https://deno.land/std@0.198.0/path/_resolve.ts": "3bf0287d62488cad08c3c219a9708c4a4c658c65d7b4400fd99afdc3ba10a64d", - "https://deno.land/std@0.198.0/path/_to_file_url.ts": "739bfda583598790b2e77ce227f2bb618f6ebdb939788cea47555b43970ec58c", - "https://deno.land/std@0.198.0/path/_to_namespaced_path.ts": "0d5f4caa2ed98ef7a8786286df6af804b50e38859ae897b5b5b4c8c5930a75c8", - "https://deno.land/std@0.198.0/path/_util.ts": "4e191b1bac6b3bf0c31aab42e5ca2e01a86ab5a0d2e08b75acf8585047a86221", - "https://deno.land/std@0.198.0/path/basename.ts": "6f08fbb90dbfcf320765b3abb01f995b1723f75e2534acfd5380e202c802a3aa", - "https://deno.land/std@0.198.0/path/common.ts": "ee7505ab01fd22de3963b64e46cff31f40de34f9f8de1fff6a1bd2fe79380000", - "https://deno.land/std@0.198.0/path/dirname.ts": "098996822a31b4c46e1eb52a19540d3c6f9f54b772fc8a197939eeabc29fca2f", - "https://deno.land/std@0.198.0/path/extname.ts": "9b83c62fd16505739541f7a3ab447d8972da39dbf668d47af2f93206c2480893", - "https://deno.land/std@0.198.0/path/format.ts": "cb22f95cc7853d590b87708cc9441785e760d711188facff3d225305a8213aca", - "https://deno.land/std@0.198.0/path/from_file_url.ts": "a6221cfc928928ec4d9786d767dfac98fa2ab746af0786446c9834a07b98817e", - "https://deno.land/std@0.198.0/path/glob.ts": "d479e0a695621c94d3fd7fe7abd4f9499caf32a8de13f25073451c6ef420a4e1", - "https://deno.land/std@0.198.0/path/is_absolute.ts": "6b3d36352eb7fa29edb53f9e7b09b1aeb022a3c5465764f6cc5b8c41f9736197", - "https://deno.land/std@0.198.0/path/join.ts": "4a2867ff2f3c81ffc9eb3d56dade16db6f8bd3854f269306d23dad4115089c84", - "https://deno.land/std@0.198.0/path/mod.ts": "7765507696cb321994cdacfc19ee3ba61e8e3ebf4bd98fa75a276cf5dc18ce2a", - "https://deno.land/std@0.198.0/path/normalize.ts": "7d992cd262b2deefa842d93a8ba2ed51f3949ba595b1d07f627ac2cddbc74808", - "https://deno.land/std@0.198.0/path/parse.ts": "031fe488b3497fb8312fc1dc3c3d6c2d80707edd9c661e18ee9fd20f95edf322", - "https://deno.land/std@0.198.0/path/posix.ts": "0a1c1952d132323a88736d03e92bd236f3ed5f9f079e5823fae07c8d978ee61b", - "https://deno.land/std@0.198.0/path/relative.ts": "7db80c5035016174267da16321a742d76e875215c317859a383b12f413c6f5d6", - "https://deno.land/std@0.198.0/path/resolve.ts": "103b62207726a27f28177f397008545804ecb20aaf00623af1f622b18cd80b9f", - "https://deno.land/std@0.198.0/path/separator.ts": "0fb679739d0d1d7bf45b68dacfb4ec7563597a902edbaf3c59b50d5bcadd93b1", - "https://deno.land/std@0.198.0/path/to_file_url.ts": "dd32f7a01bbf3b15b5df46796659984b372973d9b2d7d59bcf0eb990763a0cb5", - "https://deno.land/std@0.198.0/path/to_namespaced_path.ts": "4e643ab729bf49ccdc166ad48d2de262ff462938fcf2a44a4425588f4a0bd690", - "https://deno.land/std@0.198.0/path/win32.ts": "8b3f80ef7a462511d5e8020ff490edcaa0a0d118f1b1e9da50e2916bdd73f9dd", - "https://deno.land/std@0.198.0/testing/asserts.ts": "b4e4b1359393aeff09e853e27901a982c685cb630df30426ed75496961931946", - "https://deno.land/std@0.198.0/testing/snapshot.ts": "70263f752313814349bbab3707e07a11d6fb0577716ed51df5ec56d54350d8cb", - "https://deno.land/x/pyro@0.6.1/page.ts": "48fe33cf18df653633cf4bc28b93d2f70d19556354a09409d03ce7bc57cdf4ee", - "https://deno.land/x/pyro@0.6.1/src/lib/types.ts": "e7c34471ce0a06fde7d9dd3aef02b4f6a95b03e9eda20b75361f8799e9b3637e", - "https://esm.sh/preact@10.16.0/jsx-runtime": "9e67b64a5b48299c77d30bffc213735fdcf4b3b5d4ad8ff8d4136f246de5fa34", - "https://esm.sh/stable/preact@10.16.0/denonext/jsx-runtime.js": "64770c709df77c4b64b79f84a4abf6189fd0c3ea461121870eca0cf2bcca87b0", - "https://esm.sh/stable/preact@10.16.0/denonext/preact.mjs": "01dc8bdf124926c611c0711081b9c162cf2735cccad7c2bc9914766f633ddb1d" + "https://deno.land/std@0.201.0/assert/_constants.ts": "8a9da298c26750b28b326b297316cdde860bc237533b07e1337c021379e6b2a9", + "https://deno.land/std@0.201.0/assert/_diff.ts": "1a3c044aedf77647d6cac86b798c6417603361b66b54c53331b312caeb447aea", + "https://deno.land/std@0.201.0/assert/_format.ts": "a69126e8a469009adf4cf2a50af889aca364c349797e63174884a52ff75cf4c7", + "https://deno.land/std@0.201.0/assert/assert.ts": "9a97dad6d98c238938e7540736b826440ad8c1c1e54430ca4c4e623e585607ee", + "https://deno.land/std@0.201.0/assert/assert_equals.ts": "d8ec8a22447fbaf2fc9d7c3ed2e66790fdb74beae3e482855d75782218d68227", + "https://deno.land/std@0.201.0/assert/assertion_error.ts": "4d0bde9b374dfbcbe8ac23f54f567b77024fb67dbb1906a852d67fe050d42f56", + "https://deno.land/std@0.201.0/assert/equal.ts": "9f1a46d5993966d2596c44e5858eec821859b45f783a5ee2f7a695dfc12d8ece", + "https://deno.land/std@0.201.0/async/deadline.ts": "58f72a3cc0fcb731b2cc055ba046f4b5be3349ff6bf98f2e793c3b969354aab2", + "https://deno.land/std@0.201.0/async/delay.ts": "a6142eb44cdd856b645086af2b811b1fcce08ec06bb7d50969e6a872ee9b8659", + "https://deno.land/std@0.201.0/async/retry.ts": "296fb9c323e1325a69bee14ba947e7da7409a8dd9dd646d70cb51ea0d301f24e", + "https://deno.land/std@0.201.0/fmt/colors.ts": "87544aa2bc91087bb37f9c077970c85bfb041b48e4c37356129d7b450a415b6f", + "https://deno.land/std@0.201.0/fs/_util.ts": "fbf57dcdc9f7bc8128d60301eece608246971a7836a3bb1e78da75314f08b978", + "https://deno.land/std@0.201.0/fs/ensure_dir.ts": "dc64c4c75c64721d4e3fb681f1382f803ff3d2868f08563ff923fdd20d071c40", + "https://deno.land/std@0.201.0/fs/ensure_file.ts": "39ac83cc283a20ec2735e956adf5de3e8a3334e0b6820547b5772f71c49ae083", + "https://deno.land/std@0.201.0/path/_basename.ts": "057d420c9049821f983f784fd87fa73ac471901fb628920b67972b0f44319343", + "https://deno.land/std@0.201.0/path/_constants.ts": "e49961f6f4f48039c0dfed3c3f93e963ca3d92791c9d478ac5b43183413136e0", + "https://deno.land/std@0.201.0/path/_dirname.ts": "355e297236b2218600aee7a5301b937204c62e12da9db4b0b044993d9e658395", + "https://deno.land/std@0.201.0/path/_extname.ts": "eaaa5aae1acf1f03254d681bd6a8ce42a9cb5b7ff2213a9d4740e8ab31283664", + "https://deno.land/std@0.201.0/path/_format.ts": "4a99270d6810f082e614309164fad75d6f1a483b68eed97c830a506cc589f8b4", + "https://deno.land/std@0.201.0/path/_from_file_url.ts": "6eadfae2e6f63ad9ee46b26db4a1b16583055c0392acedfb50ed2fc694b6f581", + "https://deno.land/std@0.201.0/path/_interface.ts": "6471159dfbbc357e03882c2266d21ef9afdb1e4aa771b0545e90db58a0ba314b", + "https://deno.land/std@0.201.0/path/_is_absolute.ts": "05dac10b5e93c63198b92e3687baa2be178df5321c527dc555266c0f4f51558c", + "https://deno.land/std@0.201.0/path/_join.ts": "815f5e85b042285175b1492dd5781240ce126c23bd97bad6b8211fe7129c538e", + "https://deno.land/std@0.201.0/path/_normalize.ts": "a19ec8706b2707f9dd974662a5cd89fad438e62ab1857e08b314a8eb49a34d81", + "https://deno.land/std@0.201.0/path/_os.ts": "d932f56d41e4f6a6093d56044e29ce637f8dcc43c5a90af43504a889cf1775e3", + "https://deno.land/std@0.201.0/path/_parse.ts": "0f9b0ff43682dd9964eb1c4398610c4e165d8db9d3ac9d594220217adf480cfa", + "https://deno.land/std@0.201.0/path/_relative.ts": "27bdeffb5311a47d85be26d37ad1969979359f7636c5cd9fcf05dcd0d5099dc5", + "https://deno.land/std@0.201.0/path/_resolve.ts": "7a3616f1093735ed327e758313b79c3c04ea921808ca5f19ddf240cb68d0adf6", + "https://deno.land/std@0.201.0/path/_to_file_url.ts": "a141e4a525303e1a3a0c0571fd024552b5f3553a2af7d75d1ff3a503dcbb66d8", + "https://deno.land/std@0.201.0/path/_to_namespaced_path.ts": "0d5f4caa2ed98ef7a8786286df6af804b50e38859ae897b5b5b4c8c5930a75c8", + "https://deno.land/std@0.201.0/path/_util.ts": "4e191b1bac6b3bf0c31aab42e5ca2e01a86ab5a0d2e08b75acf8585047a86221", + "https://deno.land/std@0.201.0/path/basename.ts": "bdfa5a624c6a45564dc6758ef2077f2822978a6dbe77b0a3514f7d1f81362930", + "https://deno.land/std@0.201.0/path/common.ts": "ee7505ab01fd22de3963b64e46cff31f40de34f9f8de1fff6a1bd2fe79380000", + "https://deno.land/std@0.201.0/path/dirname.ts": "b6533f4ee4174a526dec50c279534df5345836dfdc15318400b08c62a62a39dd", + "https://deno.land/std@0.201.0/path/extname.ts": "62c4b376300795342fe1e4746c0de518b4dc9c4b0b4617bfee62a2973a9555cf", + "https://deno.land/std@0.201.0/path/format.ts": "110270b238514dd68455a4c54956215a1aff7e37e22e4427b7771cefe1920aa5", + "https://deno.land/std@0.201.0/path/from_file_url.ts": "9f5cb58d58be14c775ec2e57fc70029ac8b17ed3bd7fe93e475b07280adde0ac", + "https://deno.land/std@0.201.0/path/glob.ts": "593e2c3573883225c25c5a21aaa8e9382a696b8e175ea20a3b6a1471ad17aaed", + "https://deno.land/std@0.201.0/path/is_absolute.ts": "0b92eb35a0a8780e9f16f16bb23655b67dace6a8e0d92d42039e518ee38103c1", + "https://deno.land/std@0.201.0/path/join.ts": "31c5419f23d91655b08ec7aec403f4e4cd1a63d39e28f6e42642ea207c2734f8", + "https://deno.land/std@0.201.0/path/mod.ts": "6e1efb0b13121463aedb53ea51dabf5639a3172ab58c89900bbb72b486872532", + "https://deno.land/std@0.201.0/path/normalize.ts": "6ea523e0040979dd7ae2f1be5bf2083941881a252554c0f32566a18b03021955", + "https://deno.land/std@0.201.0/path/parse.ts": "be8de342bb9e1924d78dc4d93c45215c152db7bf738ec32475560424b119b394", + "https://deno.land/std@0.201.0/path/posix.ts": "0a1c1952d132323a88736d03e92bd236f3ed5f9f079e5823fae07c8d978ee61b", + "https://deno.land/std@0.201.0/path/relative.ts": "8bedac226afd360afc45d451a6c29fabceaf32978526bcb38e0c852661f66c61", + "https://deno.land/std@0.201.0/path/resolve.ts": "133161e4949fc97f9ca67988d51376b0f5eef8968a6372325ab84d39d30b80dc", + "https://deno.land/std@0.201.0/path/separator.ts": "40a3e9a4ad10bef23bc2cd6c610291b6c502a06237c2c4cd034a15ca78dedc1f", + "https://deno.land/std@0.201.0/path/to_file_url.ts": "00e6322373dd51ad109956b775e4e72e5f9fa68ce2c6b04e4af2a6eed3825d31", + "https://deno.land/std@0.201.0/path/to_namespaced_path.ts": "1b1db3055c343ab389901adfbda34e82b7386bcd1c744d54f9c1496ee0fd0c3d", + "https://deno.land/std@0.201.0/path/win32.ts": "8b3f80ef7a462511d5e8020ff490edcaa0a0d118f1b1e9da50e2916bdd73f9dd", + "https://deno.land/std@0.201.0/testing/snapshot.ts": "fd91f03c258c316bc9faf815846d85e80e0c82622b28ee44b57ec66dd91d3408" } } diff --git a/docs/pages/guides/navigation.md b/docs/pages/guides/navigation.md index 7a7c261..3a1d19b 100644 --- a/docs/pages/guides/navigation.md +++ b/docs/pages/guides/navigation.md @@ -28,7 +28,7 @@ await button!.click(); // Type in the search input const input = await page.$("#search-input"); -await input!.type("pyro", { delay: 100 }); +await input!.type("pyro", { delay: 1000 }); // Wait for the search results to come back await page.waitForNetworkIdle({ idleConnections: 0, idleTime: 1000 }); diff --git a/docs/pages/showcase.tsx b/docs/pages/showcase.tsx index 97f2fd8..cd32625 100644 --- a/docs/pages/showcase.tsx +++ b/docs/pages/showcase.tsx @@ -1,7 +1,7 @@ -import { ensureDirSync } from "https://deno.land/std@0.198.0/fs/ensure_dir.ts"; +import { ensureDirSync } from "https://deno.land/std@0.201.0/fs/ensure_dir.ts"; import { launch } from "../../mod.ts"; import { type PageProps } from "https://deno.land/x/pyro@0.6.1/page.ts"; -import { ensureFileSync } from "https://deno.land/std@0.198.0/fs/ensure_file.ts"; +import { ensureFileSync } from "https://deno.land/std@0.201.0/fs/ensure_file.ts"; export const config = { title: "Showcase", diff --git a/examples/navigation.ts b/examples/navigation.ts index 2ca88e0..91c8969 100644 --- a/examples/navigation.ts +++ b/examples/navigation.ts @@ -12,7 +12,7 @@ await button!.click(); // Type in the search input const input = await page.$("#search-input"); -await input!.type("pyro", { delay: 100 }); +await input!.type("pyro", { delay: 1000 }); // Wait for the search results to come back await page.waitForNetworkIdle({ idleConnections: 0, idleTime: 1000 }); diff --git a/src/browser.ts b/src/browser.ts index 9c624fe..35a6907 100644 --- a/src/browser.ts +++ b/src/browser.ts @@ -1,4 +1,4 @@ -import { retry } from "https://deno.land/std@0.198.0/async/retry.ts"; +import { retry } from "https://deno.land/std@0.201.0/async/retry.ts"; import { Celestial, PROTOCOL_VERSION } from "../bindings/celestial.ts"; import { getBinary } from "./cache.ts"; diff --git a/src/cache.ts b/src/cache.ts index 6412ed2..43439ad 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -1,5 +1,5 @@ -import { ensureDirSync } from "https://deno.land/std@0.198.0/fs/ensure_dir.ts"; -import { resolve } from "https://deno.land/std@0.198.0/path/mod.ts"; +import { ensureDirSync } from "https://deno.land/std@0.201.0/fs/ensure_dir.ts"; +import { resolve } from "https://deno.land/std@0.201.0/path/mod.ts"; export const SUPPORTED_VERSIONS = { chrome: "118.0.5943.0", diff --git a/src/dialog.ts b/src/dialog.ts index 9a4a051..f44cf52 100644 --- a/src/dialog.ts +++ b/src/dialog.ts @@ -11,36 +11,27 @@ export type DialogType = Page_DialogType; */ export class Dialog { #celestial: Celestial; - #defaultValue: string; - #message: string; - #type: DialogType; - - constructor(celestial: Celestial, config: Page_javascriptDialogOpening) { - this.#celestial = celestial; - this.#defaultValue = config.defaultPrompt ?? ""; - this.#message = config.message; - this.#type = config.type; - } /** * The default value of the prompt, or an empty string if the dialog is not a prompt. */ - get defaultValue() { - return this.#defaultValue; - } + readonly defaultValue: string; /** * The message displayed in the dialog. */ - get message() { - return this.#message; - } + readonly message: string; /** * The type of the dialog. */ - get type() { - return this.#type; + readonly type: DialogType; + + constructor(celestial: Celestial, config: Page_javascriptDialogOpening) { + this.#celestial = celestial; + this.defaultValue = config.defaultPrompt ?? ""; + this.message = config.message; + this.type = config.type; } /** diff --git a/src/elementHandle.ts b/src/elementHandle.ts index b4bc7f8..a3af89b 100644 --- a/src/elementHandle.ts +++ b/src/elementHandle.ts @@ -1,4 +1,4 @@ -import { deadline } from "https://deno.land/std@0.198.0/async/deadline.ts"; +import { deadline } from "https://deno.land/std@0.201.0/async/deadline.ts"; import { Celestial } from "../bindings/celestial.ts"; import { KeyboardTypeOptions } from "./keyboard.ts"; diff --git a/src/fileChooser.ts b/src/fileChooser.ts new file mode 100644 index 0000000..61b7504 --- /dev/null +++ b/src/fileChooser.ts @@ -0,0 +1,35 @@ +import { resolve } from "https://deno.land/std@0.201.0/path/resolve.ts"; + +import type { + Celestial, + Page_fileChooserOpened, +} from "../bindings/celestial.ts"; + +/** + * Dialog provides an api for managing a page's dialog events. + */ +export class FileChooser { + #celestial: Celestial; + #backendNodeId: number; + + /** + * Whether this file chooser accepts multiple files. + */ + readonly multiple: boolean; + + constructor(celestial: Celestial, config: Required) { + this.multiple = config.mode === "selectMultiple"; + this.#celestial = celestial; + this.#backendNodeId = config.backendNodeId; + } + + /** + * Sets the value of the file input this chooser is associated with. If some of the filePaths are relative paths, then they are resolved relative to the current working directory. For empty array, clears the selected files. + */ + async setFiles(files: string[]) { + await this.#celestial.DOM.setFileInputFiles({ + files: files.map((file) => resolve(file)), + backendNodeId: this.#backendNodeId, + }); + } +} diff --git a/src/page.ts b/src/page.ts index baabf5d..8949882 100644 --- a/src/page.ts +++ b/src/page.ts @@ -1,4 +1,4 @@ -import { deadline } from "https://deno.land/std@0.198.0/async/deadline.ts"; +import { deadline } from "https://deno.land/std@0.201.0/async/deadline.ts"; import { Celestial, Network_Cookie } from "../bindings/celestial.ts"; import { Browser } from "./browser.ts"; @@ -8,6 +8,7 @@ import { Mouse } from "./mouse.ts"; import { Keyboard } from "./keyboard.ts"; import { Touchscreen } from "./touchscreen.ts"; import { Dialog } from "./dialog.ts"; +import { FileChooser } from "./fileChooser.ts"; export type DeleteCookieOptions = Omit< Parameters[0], @@ -30,7 +31,7 @@ export type ScreenshotOptions = Parameters< export type Cookie = Network_Cookie; export type WaitForOptions = { - waitUntil?: "load" | "networkidle0" | "networkidle2"; + waitUntil?: "none" | "load" | "networkidle0" | "networkidle2"; }; export type WaitForNetworkIdleOptions = { @@ -50,6 +51,7 @@ export interface EvaluateOptions { export interface PageEventMap { "dialog": DialogEvent; + "filechooser": FileChooserEvent; } export class DialogEvent extends CustomEvent { @@ -58,6 +60,12 @@ export class DialogEvent extends CustomEvent { } } +export class FileChooserEvent extends CustomEvent { + constructor(detail: FileChooser) { + super("filechooser", { detail }); + } +} + /** * Page provides methods to interact with a single tab in the browser */ @@ -96,6 +104,16 @@ export class Page extends EventTarget { ); }); + this.#celestial.addEventListener("Page.fileChooserOpened", (e) => { + const { frameId, mode, backendNodeId } = e.detail; + if (!backendNodeId) return; + this.dispatchEvent( + new FileChooserEvent( + new FileChooser(this.#celestial, { frameId, mode, backendNodeId }), + ), + ); + }); + this.mouse = new Mouse(this.#celestial); this.keyboard = new Keyboard(this.#celestial); this.touchscreen = new Touchscreen(this.#celestial); @@ -378,6 +396,19 @@ export class Page extends EventTarget { return this.#url; } + waitForEvent( + event: T, + ): Promise { + return new Promise((resolve) => { + this.addEventListener( + event, + (e) => + resolve(e.detail as unknown as Promise), + { once: true }, + ); + }); + } + /** * Runs a function in the context of the page until it returns a truthy value. */ @@ -406,6 +437,10 @@ export class Page extends EventTarget { async waitForNavigation(options?: WaitForOptions) { options = options ?? { waitUntil: "networkidle2" }; + if (options.waitUntil === "none") { + return; + } + if (options.waitUntil !== "load") { await this.waitForNavigation({ waitUntil: "load" }); } diff --git a/src/util.ts b/src/util.ts index 62c1c0d..4f2d2fa 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,5 +1,5 @@ -import { deadline } from "https://deno.land/std@0.198.0/async/deadline.ts"; -import { retry } from "https://deno.land/std@0.198.0/async/retry.ts"; +import { deadline } from "https://deno.land/std@0.201.0/async/deadline.ts"; +import { retry } from "https://deno.land/std@0.201.0/async/retry.ts"; export const BASE_URL = "http://localhost:9222"; diff --git a/tests/dialog_test.ts b/tests/dialog_test.ts index 2e9382a..e237e67 100644 --- a/tests/dialog_test.ts +++ b/tests/dialog_test.ts @@ -1,4 +1,4 @@ -import { assertEquals } from "https://deno.land/std@0.198.0/assert/assert_equals.ts"; +import { assertEquals } from "https://deno.land/std@0.201.0/assert/assert_equals.ts"; import { launch } from "../mod.ts"; @@ -26,6 +26,32 @@ Deno.test("Accepting basic alert", async () => { await browser.close(); }); +Deno.test("Accepting basic alert with playwright-like syntax", async () => { + // Launch browser + const browser = await launch(); + + // Open the webpage + const page = await browser.newPage(); + + // listen for dialog events + const dialogPromise = page.waitForEvent("dialog"); + + // navigate to a page with an alert + // note: waitUntil: "none" is required because we're using a data url + await page.goto("data:text/html,", { + waitUntil: "none", + }); + + // handle dialog + const dialog = await dialogPromise; + assertEquals(dialog.message, "hi"); + assertEquals(dialog.type, "alert"); + await dialog.accept(); + + // Close browser + await browser.close(); +}); + Deno.test("Accepting prompt", async () => { // Launch browser const browser = await launch(); @@ -75,3 +101,31 @@ Deno.test("Declining comfirm", async () => { // Close browser await browser.close(); }); + +Deno.test("Input choose file", async () => { + // Launch browser + const browser = await launch(); + + // Open the webpage + const page = await browser.newPage(); + + // navigate to a page with an alert + await page.goto('data:text/html,', { + waitUntil: "none", + }); + + // click input and handle file chooser + const element = await page.$("input"); + + const [fileChooser] = await Promise.all([ + page.waitForEvent("filechooser"), + element?.click(), + ]); + + assertEquals(fileChooser.multiple, false); + + await fileChooser.setFiles(["./tests/assets/file.txt"]); + + // Close browser + await browser.close(); +}); diff --git a/tests/evaluate_test.ts b/tests/evaluate_test.ts index 7f9e451..cbc48ea 100644 --- a/tests/evaluate_test.ts +++ b/tests/evaluate_test.ts @@ -1,5 +1,5 @@ -import { assertEquals } from "https://deno.land/std@0.198.0/assert/assert_equals.ts"; -import { assertSnapshot } from "https://deno.land/std@0.198.0/testing/snapshot.ts"; +import { assertEquals } from "https://deno.land/std@0.201.0/assert/assert_equals.ts"; +import { assertSnapshot } from "https://deno.land/std@0.201.0/testing/snapshot.ts"; import { launch } from "../mod.ts"; diff --git a/tests/extract_test.ts b/tests/extract_test.ts index 89bfd21..b12be8c 100644 --- a/tests/extract_test.ts +++ b/tests/extract_test.ts @@ -1,4 +1,4 @@ -import { assertSnapshot } from "https://deno.land/std@0.198.0/testing/snapshot.ts"; +import { assertSnapshot } from "https://deno.land/std@0.201.0/testing/snapshot.ts"; import { launch } from "../mod.ts"; diff --git a/tests/stealth_test.ts b/tests/stealth_test.ts index 511acf7..03abad9 100644 --- a/tests/stealth_test.ts +++ b/tests/stealth_test.ts @@ -1,4 +1,4 @@ -import { assert } from "https://deno.land/std@0.198.0/assert/assert.ts"; +import { assert } from "https://deno.land/std@0.201.0/assert/assert.ts"; import { launch } from "../mod.ts"; diff --git a/tests/wait_test.ts b/tests/wait_test.ts index bbb0a6d..ab29b6e 100644 --- a/tests/wait_test.ts +++ b/tests/wait_test.ts @@ -1,4 +1,4 @@ -import { assertSnapshot } from "https://deno.land/std@0.198.0/testing/snapshot.ts"; +import { assertSnapshot } from "https://deno.land/std@0.201.0/testing/snapshot.ts"; import { launch } from "../mod.ts";