From 6d0aba0f343657d30c65cddcf62b29a8e6488092 Mon Sep 17 00:00:00 2001 From: fetsorn Date: Thu, 11 Jul 2024 18:59:58 +0400 Subject: [PATCH] Merge all forks upstream + latest spago and fix tests (#3) * Fix compiling errors building with purs/psc-set 0.14.2 * Remove bower and pulp * Add pacakge-lock.json * Update playwright minimum version * evaluation needs to be one expression/statement * Add connect/connectOverCDP functions * Convert FFI to more modern JS * Add bindings for focus, fill, connect among others * Make ready for 0.15 but drop tests * Use milliseconds for timeouts * update spago and esm * fix tests * Revert "fix tests" This reverts commit aec92cb08eb0727bf32f42332059fc8efbc15ad6. * fix effectfulGetter * add package-lock.json * update .gitignore * update CI, aff affCall to context --------- Co-authored-by: kamoii <> Co-authored-by: Mark Eibes Co-authored-by: phtz --- .github/workflows/ci.yml | 3 +- .gitignore | 2 + bower.json | 17 - package-lock.json | 57 ++ package.json | 5 +- packages.dhall | 42 -- spago.dhall | 29 - spago.lock | 1386 +++++++++++++++++++++++++++++++++++ spago.yaml | 30 + src/Playwright.js | 26 +- src/Playwright.purs | 74 +- src/Playwright/Data.js | 49 +- src/Playwright/Data.purs | 5 + src/Playwright/Download.js | 23 +- src/Playwright/Event.js | 16 +- src/Playwright/Internal.js | 67 +- src/Playwright/JSHandle.js | 24 +- src/Playwright/Options.purs | 49 +- src/Playwright/Response.js | 23 +- src/Playwright/Types.purs | 14 + test/Main.purs | 27 +- test/TestUtils.js | 4 +- 22 files changed, 1711 insertions(+), 261 deletions(-) delete mode 100644 bower.json create mode 100644 package-lock.json delete mode 100644 packages.dhall delete mode 100644 spago.dhall create mode 100644 spago.lock create mode 100644 spago.yaml create mode 100644 src/Playwright/Types.purs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 091949d..1c5d11e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,5 +16,6 @@ jobs: run: | PATH="$PATH:./node_modules/.bin/" npm install - npm install spago purescript + npm install spago@next purescript + npx playwright install --with-deps chromium spago test diff --git a/.gitignore b/.gitignore index 20e090a..f249be1 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ /.psc* /.purs* /.psa* +/.spago/ +/.DS_Store diff --git a/bower.json b/bower.json deleted file mode 100644 index 8e2d49a..0000000 --- a/bower.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "name": "purescript-playwright", - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "output" - ], - "dependencies": { - "purescript-prelude": "^4.1.1", - "purescript-console": "^4.4.0", - "purescript-effect": "^2.0.1" - }, - "devDependencies": { - "purescript-psci-support": "^4.0.0" - } -} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..0417f45 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,57 @@ +{ + "name": "purescript-playwright", + "version": "0.0.1", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "purescript-playwright", + "version": "0.0.1", + "license": "BSD-3-Clause", + "dependencies": { + "playwright": "^1.45.1" + } + }, + "node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/playwright": { + "version": "1.45.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.45.1.tgz", + "integrity": "sha512-Hjrgae4kpSQBr98nhCj3IScxVeVUixqj+5oyif8TdIn2opTCPEzqAqNMeK42i3cWDCVu9MI+ZsGWw+gVR4ISBg==", + "dependencies": { + "playwright-core": "1.45.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=18" + }, + "optionalDependencies": { + "fsevents": "2.3.2" + } + }, + "node_modules/playwright-core": { + "version": "1.45.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.45.1.tgz", + "integrity": "sha512-LF4CUUtrUu2TCpDw4mcrAIuYrEjVDfT1cHbJMfwnE2+1b8PZcFzPNgvZCvq2JfQ4aTjRCCHw5EJ2tmr2NSzdPg==", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=18" + } + } + } +} diff --git a/package.json b/package.json index a45a63c..2c3123f 100644 --- a/package.json +++ b/package.json @@ -7,11 +7,8 @@ "test": "test" }, "dependencies": { - "bower": "^1.8.8", - "playwright": "^1.3.0", - "pulp": "^15.0.0" + "playwright": "^1.45.1" }, - "devDependencies": {}, "scripts": { "test": "pulp test" }, diff --git a/packages.dhall b/packages.dhall deleted file mode 100644 index 56004e1..0000000 --- a/packages.dhall +++ /dev/null @@ -1,42 +0,0 @@ -let upstream = - https://github.com/purescript/package-sets/releases/download/psc-0.14.2-20210629/packages.dhall sha256:534c490bb73cae75adb5a39871142fd8db5c2d74c90509797a80b8bb0d5c3f7b - -let overrides = - { untagged-union = - { dependencies = - [ "assert" - , "console" - , "effect" - , "foreign" - , "foreign-object" - , "literals" - , "maybe" - , "newtype" - , "psci-support" - , "tuples" - , "unsafe-coerce" - ] - , repo = "https://github.com/jvliwanag/purescript-untagged-union.git" - , version = "v0.3.0" - } - } - -let additions = - { literals = - { dependencies = - [ "assert" - , "effect" - , "console" - , "integers" - , "numbers" - , "partial" - , "psci-support" - , "unsafe-coerce" - , "typelevel-prelude" - ] - , repo = "https://github.com/jvliwanag/purescript-literals.git" - , version = "7b2ae20f77c67b7e419a92fdd0dc7a09b447b18e" - } - } - -in upstream ⫽ overrides ⫽ additions diff --git a/spago.dhall b/spago.dhall deleted file mode 100644 index 12f6490..0000000 --- a/spago.dhall +++ /dev/null @@ -1,29 +0,0 @@ -{ name = "playwright" -, dependencies = - [ "argonaut-core" - , "console" - , "effect" - , "prelude" - , "psci-support" - , "aff-promise" - , "test-unit" - , "untagged-union" - , "node-buffer" - , "node-fs-aff" - , "undefined" - , "aff" - , "either" - , "exceptions" - , "foreign" - , "foreign-object" - , "literals" - , "maybe" - , "node-streams" - , "ordered-collections" - , "refs" - , "strings" - , "transformers" - ] -, packages = ./packages.dhall -, sources = [ "src/**/*.purs", "test/**/*.purs" ] -} diff --git a/spago.lock b/spago.lock new file mode 100644 index 0000000..5d65298 --- /dev/null +++ b/spago.lock @@ -0,0 +1,1386 @@ +workspace: + packages: + playwright: + path: ./ + dependencies: + - aff + - aff-promise + - argonaut-core + - console + - datetime + - effect + - either + - exceptions + - foreign + - foreign-object + - literals + - maybe + - node-buffer + - node-fs + - node-streams + - ordered-collections + - prelude + - psci-support + - refs + - strings + - test-unit + - transformers + - untagged-union + test_dependencies: [] + build_plan: + - aff + - aff-promise + - argonaut-core + - arraybuffer-types + - arrays + - assert + - avar + - bifunctors + - catenable-lists + - console + - const + - contravariant + - control + - datetime + - distributive + - effect + - either + - enums + - exceptions + - exists + - foldable-traversable + - foreign + - foreign-object + - free + - functions + - functors + - gen + - identity + - integers + - invariant + - js-date + - js-timers + - lazy + - lcg + - lists + - literals + - maybe + - newtype + - node-buffer + - node-event-emitter + - node-fs + - node-path + - node-streams + - nonempty + - now + - nullable + - numbers + - ordered-collections + - orders + - parallel + - partial + - prelude + - profunctor + - psci-support + - quickcheck + - random + - record + - refs + - safe-coerce + - st + - strings + - tailrec + - test-unit + - transformers + - tuples + - type-equality + - typelevel-prelude + - unfoldable + - unsafe-coerce + - untagged-union + package_set: + address: + registry: 53.2.0 + compiler: ">=0.15.15 <0.16.0" + content: + abc-parser: 2.0.1 + ace: 9.1.0 + address-rfc2821: 0.1.1 + aff: 7.1.0 + aff-bus: 6.0.0 + aff-coroutines: 9.0.0 + aff-promise: 4.0.0 + aff-retry: 2.0.0 + affjax: 13.0.0 + affjax-node: 1.0.0 + affjax-web: 1.0.0 + ansi: 7.0.0 + apexcharts: 0.5.0 + applicative-phases: 1.0.0 + argonaut: 9.0.0 + argonaut-aeson-generic: 0.4.1 + argonaut-codecs: 9.1.0 + argonaut-core: 7.0.0 + argonaut-generic: 8.0.0 + argonaut-traversals: 10.0.0 + argparse-basic: 2.0.0 + array-builder: 0.1.2 + array-search: 0.6.0 + arraybuffer: 13.2.0 + arraybuffer-builder: 3.1.0 + arraybuffer-types: 3.0.2 + arrays: 7.3.0 + arrays-extra: 0.6.1 + arrays-zipper: 2.0.1 + ask: 1.0.0 + assert: 6.0.0 + assert-multiple: 0.4.0 + avar: 5.0.0 + b64: 0.0.8 + barbies: 1.0.1 + barlow-lens: 0.9.0 + bifunctors: 6.0.0 + bigints: 7.0.1 + bolson: 0.3.9 + bookhound: 0.1.7 + bower-json: 3.0.0 + call-by-name: 4.0.1 + canvas: 6.0.0 + canvas-action: 9.0.0 + cartesian: 1.0.6 + catenable-lists: 7.0.0 + cbor-stream: 1.3.0 + chameleon: 1.0.0 + chameleon-halogen: 1.0.3 + chameleon-react-basic: 1.1.0 + chameleon-styled: 2.5.0 + chameleon-transformers: 1.0.0 + channel: 1.0.0 + checked-exceptions: 3.1.1 + choku: 1.0.1 + classless: 0.1.1 + classless-arbitrary: 0.1.1 + classless-decode-json: 0.1.1 + classless-encode-json: 0.1.3 + classnames: 2.0.0 + codec: 6.1.0 + codec-argonaut: 10.0.0 + codec-json: 1.2.0 + colors: 7.0.1 + concur-core: 0.5.0 + concur-react: 0.5.0 + concurrent-queues: 3.0.0 + console: 6.1.0 + const: 6.0.0 + contravariant: 6.0.0 + control: 6.0.0 + convertable-options: 1.0.0 + coroutines: 7.0.0 + css: 6.0.0 + css-frameworks: 1.0.1 + csv-stream: 2.3.0 + data-mvc: 0.0.2 + datetime: 6.1.0 + datetime-parsing: 0.2.0 + debounce: 0.1.0 + debug: 6.0.2 + decimals: 7.1.0 + default-values: 1.0.1 + deku: 0.9.23 + deno: 0.0.5 + dissect: 1.0.0 + distributive: 6.0.0 + dom-filereader: 7.0.0 + dom-indexed: 12.0.0 + dom-simple: 0.4.0 + dotenv: 4.0.3 + droplet: 0.6.0 + dts: 1.0.0 + dual-numbers: 1.0.2 + dynamic-buffer: 3.0.1 + echarts-simple: 0.0.1 + effect: 4.0.0 + either: 6.1.0 + elmish: 0.11.3 + elmish-enzyme: 0.1.1 + elmish-hooks: 0.10.0 + elmish-html: 0.8.3 + elmish-testing-library: 0.3.2 + email-validate: 7.0.0 + encoding: 0.0.9 + enums: 6.0.1 + env-names: 0.4.0 + error: 2.0.0 + eta-conversion: 0.3.2 + exceptions: 6.1.0 + exists: 6.0.0 + exitcodes: 4.0.0 + expect-inferred: 3.0.0 + ezfetch: 1.0.0 + fahrtwind: 2.0.0 + fallback: 0.1.0 + fast-vect: 1.2.0 + fetch: 4.1.0 + fetch-argonaut: 1.0.1 + fetch-core: 5.1.0 + fetch-yoga-json: 1.1.0 + ffi-simple: 0.5.1 + fft-js: 0.1.0 + filterable: 5.0.0 + fix-functor: 0.1.0 + fixed-points: 7.0.0 + fixed-precision: 5.0.0 + flame: 1.3.0 + float32: 2.0.0 + fmt: 0.2.1 + foldable-traversable: 6.0.0 + foldable-traversable-extra: 0.0.6 + foreign: 7.0.0 + foreign-object: 4.1.0 + foreign-readwrite: 3.4.0 + forgetmenot: 0.1.0 + fork: 6.0.0 + form-urlencoded: 7.0.0 + formatters: 7.0.0 + framer-motion: 1.0.1 + free: 7.1.0 + freeap: 7.0.0 + freer-free: 0.0.1 + freet: 7.0.0 + functions: 6.0.0 + functor1: 3.0.0 + functors: 5.0.0 + fuzzy: 0.4.0 + gen: 4.0.0 + generate-values: 1.0.1 + generic-router: 0.0.1 + geojson: 0.0.5 + geometry-plane: 1.0.3 + gojs: 0.1.1 + grain: 3.0.0 + grain-router: 3.0.0 + grain-virtualized: 3.0.0 + graphs: 8.1.0 + group: 4.1.1 + halogen: 7.0.0 + halogen-bootstrap5: 5.3.2 + halogen-canvas: 1.0.0 + halogen-css: 10.0.0 + halogen-echarts-simple: 0.0.4 + halogen-formless: 4.0.3 + halogen-helix: 1.0.0 + halogen-hooks: 0.6.3 + halogen-hooks-extra: 0.9.0 + halogen-infinite-scroll: 1.1.0 + halogen-store: 0.5.4 + halogen-storybook: 2.0.0 + halogen-subscriptions: 2.0.0 + halogen-svg-elems: 8.0.0 + halogen-typewriter: 1.0.4 + halogen-vdom: 8.0.0 + halogen-vdom-string-renderer: 0.5.0 + halogen-xterm: 2.0.0 + heckin: 2.0.1 + heterogeneous: 0.6.0 + homogeneous: 0.4.0 + http-methods: 6.0.0 + httpurple: 4.0.0 + huffman: 0.4.0 + humdrum: 0.0.1 + hyrule: 2.3.8 + identity: 6.0.0 + identy: 4.0.1 + indexed-db: 1.0.0 + indexed-monad: 3.0.0 + int64: 3.0.0 + integers: 6.0.0 + interpolate: 5.0.2 + intersection-observer: 1.0.1 + invariant: 6.0.0 + jarilo: 1.0.1 + jelly: 0.10.0 + jelly-router: 0.3.0 + jelly-signal: 0.4.0 + jest: 1.0.0 + js-abort-controller: 1.0.0 + js-bigints: 2.2.1 + js-date: 8.0.0 + js-fetch: 0.2.1 + js-fileio: 3.0.0 + js-intl: 1.0.4 + js-iterators: 0.1.1 + js-maps: 0.1.2 + js-promise: 1.0.0 + js-promise-aff: 1.0.0 + js-timers: 6.1.0 + js-uri: 3.1.0 + json: 1.1.0 + json-codecs: 5.0.0 + justifill: 0.5.0 + jwt: 0.0.9 + labeled-data: 0.2.0 + language-cst-parser: 0.14.0 + lazy: 6.0.0 + lazy-joe: 1.0.0 + lcg: 4.0.0 + leibniz: 5.0.0 + leveldb: 1.0.1 + liminal: 1.0.1 + linalg: 6.0.0 + lists: 7.0.0 + literals: 1.0.2 + logging: 3.0.0 + logging-journald: 0.4.0 + lumi-components: 18.0.0 + machines: 7.0.0 + maps-eager: 0.5.0 + marionette: 1.0.0 + marionette-react-basic-hooks: 0.1.1 + marked: 0.1.0 + matrices: 5.0.1 + matryoshka: 1.0.0 + maybe: 6.0.0 + media-types: 6.0.0 + meowclient: 1.0.0 + midi: 4.0.0 + milkis: 9.0.0 + minibench: 4.0.1 + mmorph: 7.0.0 + monad-control: 5.0.0 + monad-logger: 1.3.1 + monad-loops: 0.5.0 + monad-unlift: 1.0.1 + monoid-extras: 0.0.1 + monoidal: 0.16.0 + morello: 0.4.0 + mote: 3.0.0 + motsunabe: 2.0.0 + mvc: 0.0.1 + mysql: 6.0.1 + n3: 0.1.0 + nano-id: 1.1.0 + nanoid: 0.1.0 + naturals: 3.0.0 + nested-functor: 0.2.1 + newtype: 5.0.0 + nextjs: 0.1.1 + nextui: 0.2.0 + node-buffer: 9.0.0 + node-child-process: 11.1.0 + node-event-emitter: 3.0.0 + node-execa: 5.0.0 + node-fs: 9.2.0 + node-glob-basic: 1.3.0 + node-http: 9.1.0 + node-http2: 1.1.1 + node-human-signals: 1.0.0 + node-net: 5.1.0 + node-os: 5.1.0 + node-path: 5.0.0 + node-process: 11.2.0 + node-readline: 8.1.1 + node-sqlite3: 8.0.0 + node-stream-pipes: 2.1.4 + node-streams: 9.0.0 + node-tls: 0.3.1 + node-url: 7.0.1 + node-zlib: 0.4.0 + nonempty: 7.0.0 + now: 6.0.0 + npm-package-json: 2.0.0 + nullable: 6.0.0 + numberfield: 0.1.0 + numbers: 9.0.1 + oak: 3.1.1 + oak-debug: 1.2.2 + object-maps: 0.3.0 + ocarina: 1.5.4 + open-folds: 6.3.0 + open-memoize: 6.1.0 + open-pairing: 6.1.0 + options: 7.0.0 + optparse: 5.0.1 + ordered-collections: 3.2.0 + ordered-set: 0.4.0 + orders: 6.0.0 + owoify: 1.2.0 + pairs: 9.0.1 + parallel: 7.0.0 + parsing: 10.2.0 + parsing-dataview: 3.2.4 + partial: 4.0.0 + pathy: 9.0.0 + pha: 0.13.0 + phaser: 0.7.0 + phylio: 1.1.2 + pipes: 8.0.0 + pirates-charm: 0.0.1 + pmock: 0.9.0 + point-free: 1.0.0 + pointed-list: 0.5.1 + polymorphic-vectors: 4.0.0 + posix-types: 6.0.0 + postgresql: 2.0.17 + precise: 6.0.0 + precise-datetime: 7.0.0 + prelude: 6.0.1 + prettier-printer: 3.0.0 + profunctor: 6.0.1 + profunctor-lenses: 8.0.0 + protobuf: 4.3.0 + psa-utils: 8.0.0 + psci-support: 6.0.0 + punycode: 1.0.0 + qualified-do: 2.2.0 + quantities: 12.2.0 + quickcheck: 8.0.1 + quickcheck-combinators: 0.1.3 + quickcheck-laws: 7.0.0 + quickcheck-utf8: 0.0.0 + random: 6.0.0 + rationals: 6.0.0 + rdf: 0.1.0 + react: 11.0.0 + react-aria: 0.2.0 + react-basic: 17.0.0 + react-basic-classic: 3.0.0 + react-basic-dnd: 10.1.0 + react-basic-dom: 6.1.0 + react-basic-emotion: 7.1.0 + react-basic-hooks: 8.2.0 + react-basic-storybook: 2.0.0 + react-dom: 8.0.0 + react-halo: 3.0.0 + react-icons: 1.1.5 + react-markdown: 0.1.0 + react-testing-library: 4.0.1 + react-virtuoso: 1.0.0 + reactix: 0.6.1 + read: 1.0.1 + recharts: 1.1.0 + record: 4.0.0 + record-extra: 5.0.1 + record-ptional-fields: 0.1.2 + record-studio: 1.0.4 + refs: 6.0.0 + remotedata: 5.0.1 + repr: 0.5.0 + resize-observer: 1.0.0 + resource: 2.0.1 + resourcet: 1.0.0 + result: 1.0.3 + return: 0.2.0 + ring-modules: 5.0.1 + rito: 0.3.4 + roman: 0.4.0 + rough-notation: 1.0.2 + routing: 11.0.0 + routing-duplex: 0.7.0 + run: 5.0.0 + safe-coerce: 2.0.0 + safely: 4.0.1 + school-of-music: 1.3.0 + selection-foldable: 0.2.0 + selective-functors: 1.0.1 + semirings: 7.0.0 + signal: 13.0.0 + simple-emitter: 3.0.1 + simple-i18n: 2.0.1 + simple-json: 9.0.0 + simple-json-generics: 0.2.1 + simple-ulid: 3.0.0 + sized-matrices: 1.0.0 + sized-vectors: 5.0.2 + slug: 3.0.8 + small-ffi: 4.0.1 + soundfonts: 4.1.0 + sparse-matrices: 1.3.0 + sparse-polynomials: 2.0.5 + spec: 7.6.0 + spec-mocha: 5.1.0 + spec-quickcheck: 5.0.0 + splitmix: 2.1.0 + ssrs: 1.0.0 + st: 6.2.0 + statistics: 0.3.2 + strictlypositiveint: 1.0.1 + string-parsers: 8.0.0 + strings: 6.0.1 + strings-extra: 4.0.0 + stringutils: 0.0.12 + substitute: 0.2.3 + supply: 0.2.0 + svg-parser: 3.0.0 + systemd-journald: 0.3.0 + tagged: 4.0.2 + tailrec: 6.1.0 + tecton: 0.2.1 + tecton-halogen: 0.2.0 + test-unit: 17.0.0 + thermite: 6.3.1 + thermite-dom: 0.3.1 + these: 6.0.0 + toestand: 0.9.0 + transformation-matrix: 1.0.1 + transformers: 6.1.0 + tree-rose: 4.0.2 + ts-bridge: 4.0.0 + tuples: 7.0.0 + two-or-more: 1.0.0 + type-equality: 4.0.1 + typedenv: 2.0.1 + typelevel: 6.0.0 + typelevel-lists: 2.1.0 + typelevel-peano: 1.0.1 + typelevel-prelude: 7.0.0 + typelevel-regex: 0.0.3 + typelevel-rows: 0.1.0 + typisch: 0.4.0 + uint: 7.0.0 + ulid: 3.0.1 + uncurried-transformers: 1.1.0 + undefined: 2.0.0 + undefined-is-not-a-problem: 1.1.0 + unfoldable: 6.0.0 + unicode: 6.0.0 + unique: 0.6.1 + unlift: 1.0.1 + unordered-collections: 3.1.0 + unsafe-coerce: 6.0.0 + unsafe-reference: 5.0.0 + untagged-to-tagged: 0.1.4 + untagged-union: 1.0.0 + uri: 9.0.0 + url-immutable: 1.0.0 + uuid: 9.0.0 + uuidv4: 1.0.0 + validation: 6.0.0 + variant: 8.0.0 + variant-encodings: 2.0.0 + vectorfield: 1.0.1 + vectors: 2.1.0 + versions: 7.0.0 + visx: 0.0.2 + web-clipboard: 5.0.0 + web-cssom: 2.0.0 + web-cssom-view: 0.1.0 + web-dom: 6.0.0 + web-dom-parser: 8.0.0 + web-dom-xpath: 3.0.0 + web-encoding: 3.0.0 + web-events: 4.0.0 + web-fetch: 4.0.1 + web-file: 4.0.0 + web-geometry: 0.1.0 + web-html: 4.1.0 + web-pointerevents: 2.0.0 + web-proletarian: 1.0.0 + web-promise: 3.2.0 + web-resize-observer: 2.1.0 + web-router: 1.0.0 + web-socket: 4.0.0 + web-storage: 5.0.0 + web-streams: 4.0.0 + web-touchevents: 4.0.0 + web-uievents: 5.0.0 + web-url: 2.0.0 + web-workers: 1.1.0 + web-xhr: 5.0.1 + webextension-polyfill: 0.1.0 + webgpu: 0.0.1 + which: 2.0.0 + xterm: 1.0.0 + yoga-fetch: 1.0.1 + yoga-json: 5.1.0 + yoga-om: 0.1.0 + yoga-postgres: 6.0.0 + yoga-tree: 1.0.0 + z3: 0.0.2 + zipperarray: 2.0.0 + extra_packages: {} +packages: + aff: + type: registry + version: 7.1.0 + integrity: sha256-7hOC6uQO9XBAI5FD8F33ChLjFAiZVfd4BJMqlMh7TNU= + dependencies: + - arrays + - bifunctors + - control + - datetime + - effect + - either + - exceptions + - foldable-traversable + - functions + - maybe + - newtype + - parallel + - prelude + - refs + - tailrec + - transformers + - unsafe-coerce + aff-promise: + type: registry + version: 4.0.0 + integrity: sha256-Kq5EupbUpXeUXx4JqGQE7/RTTz/H6idzWhsocwlEFhM= + dependencies: + - aff + - foreign + argonaut-core: + type: registry + version: 7.0.0 + integrity: sha256-RC82GfAjItydxrO24cdX373KHVZiLqybu19b5X8u7B4= + dependencies: + - arrays + - control + - either + - foreign-object + - functions + - gen + - maybe + - nonempty + - prelude + - strings + - tailrec + arraybuffer-types: + type: registry + version: 3.0.2 + integrity: sha256-mQKokysYVkooS4uXbO+yovmV/s8b138Ws3zQvOwIHRA= + dependencies: [] + arrays: + type: registry + version: 7.3.0 + integrity: sha256-tmcklBlc/muUtUfr9RapdCPwnlQeB3aSrC4dK85gQlc= + dependencies: + - bifunctors + - control + - foldable-traversable + - functions + - maybe + - nonempty + - partial + - prelude + - safe-coerce + - st + - tailrec + - tuples + - unfoldable + - unsafe-coerce + assert: + type: registry + version: 6.0.0 + integrity: sha256-hCSYcCw9kj3qujoDcriWhCdmrpPZoguSPDZhEMnTl3A= + dependencies: + - console + - effect + - prelude + avar: + type: registry + version: 5.0.0 + integrity: sha256-e7hf0x4hEpcygXP0LtvfvAQ49Bbj2aWtZT3gqM///0A= + dependencies: + - aff + - effect + - either + - exceptions + - functions + - maybe + bifunctors: + type: registry + version: 6.0.0 + integrity: sha256-/gZwC9YhNxZNQpnHa5BIYerCGM2jeX9ukZiEvYxm5Nw= + dependencies: + - const + - either + - newtype + - prelude + - tuples + catenable-lists: + type: registry + version: 7.0.0 + integrity: sha256-76vYENhwF4BWTBsjeLuErCH2jqVT4M3R1HX+4RwSftA= + dependencies: + - control + - foldable-traversable + - lists + - maybe + - prelude + - tuples + - unfoldable + console: + type: registry + version: 6.1.0 + integrity: sha256-CxmAzjgyuGDmt9FZW51VhV6rBPwR6o0YeKUzA9rSzcM= + dependencies: + - effect + - prelude + const: + type: registry + version: 6.0.0 + integrity: sha256-tNrxDW8D8H4jdHE2HiPzpLy08zkzJMmGHdRqt5BQuTc= + dependencies: + - invariant + - newtype + - prelude + contravariant: + type: registry + version: 6.0.0 + integrity: sha256-TP+ooAp3vvmdjfQsQJSichF5B4BPDHp3wAJoWchip6c= + dependencies: + - const + - either + - newtype + - prelude + - tuples + control: + type: registry + version: 6.0.0 + integrity: sha256-sH7Pg9E96JCPF9PIA6oQ8+BjTyO/BH1ZuE/bOcyj4Jk= + dependencies: + - newtype + - prelude + datetime: + type: registry + version: 6.1.0 + integrity: sha256-g/5X5BBegQWLpI9IWD+sY6mcaYpzzlW5lz5NBzaMtyI= + dependencies: + - bifunctors + - control + - either + - enums + - foldable-traversable + - functions + - gen + - integers + - lists + - maybe + - newtype + - numbers + - ordered-collections + - partial + - prelude + - tuples + distributive: + type: registry + version: 6.0.0 + integrity: sha256-HTDdmEnzigMl+02SJB88j+gAXDx9VKsbvR4MJGDPbOQ= + dependencies: + - identity + - newtype + - prelude + - tuples + - type-equality + effect: + type: registry + version: 4.0.0 + integrity: sha256-eBtZu+HZcMa5HilvI6kaDyVX3ji8p0W9MGKy2K4T6+M= + dependencies: + - prelude + either: + type: registry + version: 6.1.0 + integrity: sha256-6hgTPisnMWVwQivOu2PKYcH8uqjEOOqDyaDQVUchTpY= + dependencies: + - control + - invariant + - maybe + - prelude + enums: + type: registry + version: 6.0.1 + integrity: sha256-HWaD73JFLorc4A6trKIRUeDMdzE+GpkJaEOM1nTNkC8= + dependencies: + - control + - either + - gen + - maybe + - newtype + - nonempty + - partial + - prelude + - tuples + - unfoldable + exceptions: + type: registry + version: 6.1.0 + integrity: sha256-K0T89IHtF3vBY7eSAO7eDOqSb2J9kZGAcDN5+IKsF8E= + dependencies: + - effect + - either + - maybe + - prelude + exists: + type: registry + version: 6.0.0 + integrity: sha256-A0JQHpTfo1dNOj9U5/Fd3xndlRSE0g2IQWOGor2yXn8= + dependencies: + - unsafe-coerce + foldable-traversable: + type: registry + version: 6.0.0 + integrity: sha256-fLeqRYM4jUrZD5H4WqcwUgzU7XfYkzO4zhgtNc3jcWM= + dependencies: + - bifunctors + - const + - control + - either + - functors + - identity + - maybe + - newtype + - orders + - prelude + - tuples + foreign: + type: registry + version: 7.0.0 + integrity: sha256-1ORiqoS3HW+qfwSZAppHPWy4/6AQysxZ2t29jcdUMNA= + dependencies: + - either + - functions + - identity + - integers + - lists + - maybe + - prelude + - strings + - transformers + foreign-object: + type: registry + version: 4.1.0 + integrity: sha256-q24okj6mT+yGHYQ+ei/pYPj5ih6sTbu7eDv/WU56JVo= + dependencies: + - arrays + - foldable-traversable + - functions + - gen + - lists + - maybe + - prelude + - st + - tailrec + - tuples + - typelevel-prelude + - unfoldable + free: + type: registry + version: 7.1.0 + integrity: sha256-JAumgEsGSzJCNLD8AaFvuX7CpqS5yruCngi6yI7+V5k= + dependencies: + - catenable-lists + - control + - distributive + - either + - exists + - foldable-traversable + - invariant + - lazy + - maybe + - prelude + - tailrec + - transformers + - tuples + - unsafe-coerce + functions: + type: registry + version: 6.0.0 + integrity: sha256-adMyJNEnhGde2unHHAP79gPtlNjNqzgLB8arEOn9hLI= + dependencies: + - prelude + functors: + type: registry + version: 5.0.0 + integrity: sha256-zfPWWYisbD84MqwpJSZFlvM6v86McM68ob8p9s27ywU= + dependencies: + - bifunctors + - const + - contravariant + - control + - distributive + - either + - invariant + - maybe + - newtype + - prelude + - profunctor + - tuples + - unsafe-coerce + gen: + type: registry + version: 4.0.0 + integrity: sha256-f7yzAXWwr+xnaqEOcvyO3ezKdoes8+WXWdXIHDBCAPI= + dependencies: + - either + - foldable-traversable + - identity + - maybe + - newtype + - nonempty + - prelude + - tailrec + - tuples + - unfoldable + identity: + type: registry + version: 6.0.0 + integrity: sha256-4wY0XZbAksjY6UAg99WkuKyJlQlWAfTi2ssadH0wVMY= + dependencies: + - control + - invariant + - newtype + - prelude + integers: + type: registry + version: 6.0.0 + integrity: sha256-sf+sK26R1hzwl3NhXR7WAu9zCDjQnfoXwcyGoseX158= + dependencies: + - maybe + - numbers + - prelude + invariant: + type: registry + version: 6.0.0 + integrity: sha256-RGWWyYrz0Hs1KjPDA+87Kia67ZFBhfJ5lMGOMCEFoLo= + dependencies: + - control + - prelude + js-date: + type: registry + version: 8.0.0 + integrity: sha256-6TVF4DWg5JL+jRAsoMssYw8rgOVALMUHT1CuNZt8NRo= + dependencies: + - datetime + - effect + - exceptions + - foreign + - integers + - now + js-timers: + type: registry + version: 6.1.0 + integrity: sha256-znHWLSSOYw15P5DTcsAdal2lf7nGA2yayLdOZ2t5r7o= + dependencies: + - effect + lazy: + type: registry + version: 6.0.0 + integrity: sha256-lMsfFOnlqfe4KzRRiW8ot5ge6HtcU3Eyh2XkXcP5IgU= + dependencies: + - control + - foldable-traversable + - invariant + - prelude + lcg: + type: registry + version: 4.0.0 + integrity: sha256-h7ME5cthLfbgJOJdsZcSfFpwXsx4rf8YmhebU+3iSYg= + dependencies: + - effect + - integers + - maybe + - partial + - prelude + - random + lists: + type: registry + version: 7.0.0 + integrity: sha256-EKF15qYqucuXP2lT/xPxhqy58f0FFT6KHdIB/yBOayI= + dependencies: + - bifunctors + - control + - foldable-traversable + - lazy + - maybe + - newtype + - nonempty + - partial + - prelude + - tailrec + - tuples + - unfoldable + literals: + type: registry + version: 1.0.2 + integrity: sha256-RaeNZPykLhdJXYcx463xiwyC3XghrSQAqqeU28tDNW0= + dependencies: + - integers + - maybe + - numbers + - partial + - prelude + - typelevel-prelude + - unsafe-coerce + maybe: + type: registry + version: 6.0.0 + integrity: sha256-5cCIb0wPwbat2PRkQhUeZO0jcAmf8jCt2qE0wbC3v2Q= + dependencies: + - control + - invariant + - newtype + - prelude + newtype: + type: registry + version: 5.0.0 + integrity: sha256-gdrQu8oGe9eZE6L3wOI8ql/igOg+zEGB5ITh2g+uttw= + dependencies: + - prelude + - safe-coerce + node-buffer: + type: registry + version: 9.0.0 + integrity: sha256-PWE2DJ5ruBLCmeA/fUiuySEFmUJ/VuRfyrnCuVZBlu4= + dependencies: + - arraybuffer-types + - effect + - maybe + - nullable + - st + - unsafe-coerce + node-event-emitter: + type: registry + version: 3.0.0 + integrity: sha256-Qw0MjsT4xRH2j2i4K8JmRjcMKnH5z1Cw39t00q4LE4w= + dependencies: + - effect + - either + - functions + - maybe + - nullable + - prelude + - unsafe-coerce + node-fs: + type: registry + version: 9.2.0 + integrity: sha256-Sg0vkXycEzkEerX6hLccz21Ygd9w1+QSk1thotRZPGI= + dependencies: + - datetime + - effect + - either + - enums + - exceptions + - functions + - integers + - js-date + - maybe + - node-buffer + - node-path + - node-streams + - nullable + - partial + - prelude + - strings + - unsafe-coerce + node-path: + type: registry + version: 5.0.0 + integrity: sha256-pd82nQ+2l5UThzaxPdKttgDt7xlsgIDLpPG0yxDEdyE= + dependencies: + - effect + node-streams: + type: registry + version: 9.0.0 + integrity: sha256-2n6dq7YWleTDmD1Kur/ul7Cn08IvWrScgPf+0PgX2TQ= + dependencies: + - aff + - effect + - either + - exceptions + - node-buffer + - node-event-emitter + - nullable + - prelude + nonempty: + type: registry + version: 7.0.0 + integrity: sha256-54ablJZUHGvvlTJzi3oXyPCuvY6zsrWJuH/dMJ/MFLs= + dependencies: + - control + - foldable-traversable + - maybe + - prelude + - tuples + - unfoldable + now: + type: registry + version: 6.0.0 + integrity: sha256-xZ7x37ZMREfs6GCDw/h+FaKHV/3sPWmtqBZRGTxybQY= + dependencies: + - datetime + - effect + nullable: + type: registry + version: 6.0.0 + integrity: sha256-yiGBVl3AD+Guy4kNWWeN+zl1gCiJK+oeIFtZtPCw4+o= + dependencies: + - effect + - functions + - maybe + numbers: + type: registry + version: 9.0.1 + integrity: sha256-/9M6aeMDBdB4cwYDeJvLFprAHZ49EbtKQLIJsneXLIk= + dependencies: + - functions + - maybe + ordered-collections: + type: registry + version: 3.2.0 + integrity: sha256-o9jqsj5rpJmMdoe/zyufWHFjYYFTTsJpgcuCnqCO6PM= + dependencies: + - arrays + - foldable-traversable + - gen + - lists + - maybe + - partial + - prelude + - st + - tailrec + - tuples + - unfoldable + orders: + type: registry + version: 6.0.0 + integrity: sha256-nBA0g3/ai0euH8q9pSbGqk53W2q6agm/dECZTHcoink= + dependencies: + - newtype + - prelude + parallel: + type: registry + version: 7.0.0 + integrity: sha256-gUC9i4Txnx9K9RcMLsjujbwZz6BB1bnE2MLvw4GIw5o= + dependencies: + - control + - effect + - either + - foldable-traversable + - functors + - maybe + - newtype + - prelude + - profunctor + - refs + - transformers + partial: + type: registry + version: 4.0.0 + integrity: sha256-fwXerld6Xw1VkReh8yeQsdtLVrjfGiVuC5bA1Wyo/J4= + dependencies: [] + prelude: + type: registry + version: 6.0.1 + integrity: sha256-o8p6SLYmVPqzXZhQFd2hGAWEwBoXl1swxLG/scpJ0V0= + dependencies: [] + profunctor: + type: registry + version: 6.0.1 + integrity: sha256-E58hSYdJvF2Qjf9dnWLPlJKh2Z2fLfFLkQoYi16vsFk= + dependencies: + - control + - distributive + - either + - exists + - invariant + - newtype + - prelude + - tuples + psci-support: + type: registry + version: 6.0.0 + integrity: sha256-C6ql4P9TEP06hft/1Z5QumPA4yARR4VIxDdhmL1EO+Y= + dependencies: + - console + - effect + - prelude + quickcheck: + type: registry + version: 8.0.1 + integrity: sha256-ZvpccKQCvgslTXZCNmpYW4bUsFzhZd/kQUr2WmxFTGY= + dependencies: + - arrays + - console + - control + - effect + - either + - enums + - exceptions + - foldable-traversable + - gen + - identity + - integers + - lazy + - lcg + - lists + - maybe + - newtype + - nonempty + - numbers + - partial + - prelude + - record + - st + - strings + - tailrec + - transformers + - tuples + - unfoldable + random: + type: registry + version: 6.0.0 + integrity: sha256-CJ611a35MPCE7XQMp0rdC6MCn76znlhisiCRgboAG+Q= + dependencies: + - effect + - integers + record: + type: registry + version: 4.0.0 + integrity: sha256-Za5U85bTRJEfGK5Sk4hM41oXy84YQI0I8TL3WUn1Qzg= + dependencies: + - functions + - prelude + - unsafe-coerce + refs: + type: registry + version: 6.0.0 + integrity: sha256-Vgwne7jIbD3ZMoLNNETLT8Litw6lIYo3MfYNdtYWj9s= + dependencies: + - effect + - prelude + safe-coerce: + type: registry + version: 2.0.0 + integrity: sha256-a1ibQkiUcbODbLE/WAq7Ttbbh9ex+x33VCQ7GngKudU= + dependencies: + - unsafe-coerce + st: + type: registry + version: 6.2.0 + integrity: sha256-z9X0WsOUlPwNx9GlCC+YccCyz8MejC8Wb0C4+9fiBRY= + dependencies: + - partial + - prelude + - tailrec + - unsafe-coerce + strings: + type: registry + version: 6.0.1 + integrity: sha256-WssD3DbX4OPzxSdjvRMX0yvc9+pS7n5gyPv5I2Trb7k= + dependencies: + - arrays + - control + - either + - enums + - foldable-traversable + - gen + - integers + - maybe + - newtype + - nonempty + - partial + - prelude + - tailrec + - tuples + - unfoldable + - unsafe-coerce + tailrec: + type: registry + version: 6.1.0 + integrity: sha256-Xx19ECVDRrDWpz9D2GxQHHV89vd61dnXxQm0IcYQHGk= + dependencies: + - bifunctors + - effect + - either + - identity + - maybe + - partial + - prelude + - refs + test-unit: + type: registry + version: 17.0.0 + integrity: sha256-aITJ2KngFFjASmG0JjnjybaKWl9dn7Hf2B3Wk4engNs= + dependencies: + - aff + - avar + - effect + - either + - free + - js-timers + - lists + - prelude + - quickcheck + - strings + transformers: + type: registry + version: 6.1.0 + integrity: sha256-3Bm+Z6tsC/paG888XkywDngJ2JMos+JfOhRlkVfb7gI= + dependencies: + - control + - distributive + - effect + - either + - exceptions + - foldable-traversable + - identity + - lazy + - maybe + - newtype + - prelude + - st + - tailrec + - tuples + - unfoldable + tuples: + type: registry + version: 7.0.0 + integrity: sha256-1rXgTomes9105BjgXqIw0FL6Fz1lqqUTLWOumhWec1M= + dependencies: + - control + - invariant + - prelude + type-equality: + type: registry + version: 4.0.1 + integrity: sha256-Hs9D6Y71zFi/b+qu5NSbuadUQXe5iv5iWx0226vOHUw= + dependencies: [] + typelevel-prelude: + type: registry + version: 7.0.0 + integrity: sha256-uFF2ph+vHcQpfPuPf2a3ukJDFmLhApmkpTMviHIWgJM= + dependencies: + - prelude + - type-equality + unfoldable: + type: registry + version: 6.0.0 + integrity: sha256-JtikvJdktRap7vr/K4ITlxUX1QexpnqBq0G/InLr6eg= + dependencies: + - foldable-traversable + - maybe + - partial + - prelude + - tuples + unsafe-coerce: + type: registry + version: 6.0.0 + integrity: sha256-IqIYW4Vkevn8sI+6aUwRGvd87tVL36BBeOr0cGAE7t0= + dependencies: [] + untagged-union: + type: registry + version: 1.0.0 + integrity: sha256-XSSsmsOIq+JvPaXUdKCW2nGQZ2D+Ku5J6FbWj812AN0= + dependencies: + - assert + - console + - effect + - foreign + - foreign-object + - literals + - maybe + - newtype + - psci-support + - tuples + - unsafe-coerce diff --git a/spago.yaml b/spago.yaml new file mode 100644 index 0000000..884c19f --- /dev/null +++ b/spago.yaml @@ -0,0 +1,30 @@ +package: + dependencies: + - aff + - aff-promise + - argonaut-core + - console + - datetime + - effect + - either + - exceptions + - foreign + - foreign-object + - literals + - maybe + - node-buffer + - node-fs + - node-streams + - ordered-collections + - prelude + - psci-support + - refs + - strings + - test-unit + - transformers + - untagged-union + - literals + name: playwright +workspace: + packageSet: + registry: 53.2.0 diff --git a/src/Playwright.js b/src/Playwright.js index cdf08bf..bfca7f7 100644 --- a/src/Playwright.js +++ b/src/Playwright.js @@ -1,15 +1,21 @@ /* global exports */ -exports.exposeBinding_ = function (x) { - return function (name) { - return function (cb) { - return function (opts) { - return function () { - return x.exposeBinding(name, function (info, arg) { - return cb(info)(arg)(); - }, opts); - }; - }; +export const exposeBinding_ = x => name => cb => opts => () => { + return x.exposeBinding( + name, + function (info, arg) { + return cb(info)(arg)() + }, + opts + ) +} + +export const onResponse = function (page) { + return function (cb) { + return function () { + page.on('response', function (response) { + cb(response)(); + }); }; }; }; diff --git a/src/Playwright.purs b/src/Playwright.purs index e60ff96..fe95bfb 100644 --- a/src/Playwright.purs +++ b/src/Playwright.purs @@ -1,7 +1,10 @@ module Playwright ( launch + , connect + , connectOverCDP , close , contexts + , context , isConnected , version , newPage @@ -9,6 +12,7 @@ module Playwright , goBack , goto , addCookies + , cookies , hover , innerHTML , innerText @@ -40,25 +44,45 @@ module Playwright , setViewportSize , title , exposeBinding + , fill + , focus + , onResponse + , connect , module Playwright.Data , module Playwright.Options ) where +import Playwright.Options + import Control.Promise (Promise, fromAff, toAffE) import Data.String.Regex (Regex) +import Data.Unit (unit) import Effect (Effect) import Effect.Aff (Aff) import Foreign (Foreign, unsafeToForeign) import Literals.Null (Null) import Node.Buffer (Buffer) -import Playwright.Data +import Playwright.Data (Browser, BrowserContext, BrowserType, ConsoleMessage, Dialog, Download, ElementHandle, ElementState, FileChooser, Frame, JSHandle, Keyboard, Modifier, Mouse, MouseButton, Page, Raf, Request, Response, Route, ScreenshotType, Selector(..), Selectors, URL(..), WaitUntil, Worker, alt, attached, chromium, control, detached, domcontentloaded, firefox, hidden, jpg, left, load, meta, middle, networkidle, png, raf, right, shift, visible, webkit) import Playwright.Internal (effCall, effProp, affCall) -import Playwright.Options import Prelude (Unit, ($)) -import Undefined (undefined) import Untagged.Castable (class Castable) import Untagged.Union (type (|+|), UndefinedOr) +import Playwright.Types (Cookie) + +foreign import onResponse :: Page -> (Response -> Effect Unit) -> Effect Unit + +fill + :: forall o + . Castable o FillOptions + => Page -> Selector -> String -> o -> Aff Unit +fill = affCall "fill" \_ -> fill + +focus + :: forall o + . Castable o FocusOptions + => Page -> Selector -> o -> Aff Unit +focus = affCall "focus" \_ -> focus launch :: forall o @@ -67,6 +91,35 @@ launch launch = affCall "launch" \_ -> launch +type WebSocketEndpoint = String + +connect + :: forall o + . Castable o ConnectOptions + => BrowserType + -> WebSocketEndpoint + -> o + -> Aff Browser +connect = affCall "connect" \_ -> connect + +type ConnectOptions = + { timeout :: UndefinedOr Number + } + +connectOverCDP + :: forall o + . Castable o ConnectOverCDPOptions + => BrowserType + -> String + -> o + -> Aff Browser +connectOverCDP = + affCall "connectOverCDP" \_ -> connectOverCDP + +type ConnectOverCDPOptions = + { timeout :: UndefinedOr Number + } + close :: forall x . Castable x (Browser |+| BrowserContext |+| Page) @@ -116,12 +169,15 @@ goto goto = affCall "goto" \_ -> goto -type Cookie = - { name :: String - , value :: String - , url :: UndefinedOr String - } +context :: Page -> BrowserContext +context = affCall "context" \_ -> context +cookies + :: BrowserContext + -> Aff (Array Cookie) +cookies = + affCall "cookies" \_ -> cookies + addCookies :: BrowserContext -> Array Cookie @@ -320,7 +376,7 @@ waitForFunction -- ^ Function to be evaluated in browser context -> o -> Aff JSHandle -waitForFunction x s o = waitForFunction' x s (unsafeToForeign undefined) o +waitForFunction x s o = waitForFunction' x s unit o where waitForFunction' = affCall "waitForFunction" \_ -> waitForFunction' diff --git a/src/Playwright/Data.js b/src/Playwright/Data.js index 7e0636d..5f0b07b 100644 --- a/src/Playwright/Data.js +++ b/src/Playwright/Data.js @@ -1,31 +1,36 @@ /* global require exports */ -var P = require('playwright'); +import { chromium as pwChromium, firefox as pwFirefox, webkit as pwWebkit } from 'playwright'; -exports.png = "png"; -exports.jpg = "jpg"; +export const png = "png"; +export const jpg = "jpg"; -exports.chromium = P.chromium; -exports.firefox = P.firefox; -exports.webkit = P.webkit; +export const chromium = pwChromium; +export const firefox = pwFirefox; +export const webkit = pwWebkit; -exports.domcontentloaded = "domcontentloaded"; -exports.load = "load"; -exports.networkidle = "networkidle"; +export const domcontentloaded = "domcontentloaded"; +export const load = "load"; +export const networkidle = "networkidle"; -exports.alt = "Alt"; -exports.control = "Control"; -exports.meta = "Meta"; -exports.shift = "Shift"; +export const alt = "Alt"; +export const control = "Control"; +export const meta = "Meta"; +export const shift = "Shift"; -exports.null = null; +const _null = null; +export { _null as null }; -exports.left = "left"; -exports.right = "right"; -exports.middle = "middle"; +export const left = "left"; +export const right = "right"; +export const middle = "middle"; -exports.attached = "attached"; -exports.detached = "detached"; -exports.visible = "visible"; -exports.hidden = "hidden"; +export const attached = "attached"; +export const detached = "detached"; +export const visible = "visible"; +export const hidden = "hidden"; -exports.raf = "raf"; +export const raf = "raf"; + +export const strict = "Strict"; +export const lax = "Lax"; +export const none = "None"; diff --git a/src/Playwright/Data.purs b/src/Playwright/Data.purs index 57836c7..1d51267 100644 --- a/src/Playwright/Data.purs +++ b/src/Playwright/Data.purs @@ -65,5 +65,10 @@ foreign import detached :: ElementState foreign import visible :: ElementState foreign import hidden :: ElementState +foreign import data SameSite :: Type +foreign import strict :: SameSite +foreign import lax :: SameSite +foreign import none :: SameSite + foreign import data Raf :: Type foreign import raf :: Raf diff --git a/src/Playwright/Download.js b/src/Playwright/Download.js index 2e70a14..480286e 100644 --- a/src/Playwright/Download.js +++ b/src/Playwright/Download.js @@ -1,17 +1,10 @@ /* global exports */ -exports.createReadStream_ = function (Nothing) { - return function (Just) { - return function (Download) { - return function () { - return Download.createReadStream().then(function (result) { - if (result === null) { - return Nothing; - } else { - return Just(result); - } - }); - }; - }; - }; -}; +export const createReadStream_ = Nothing => Just => Download => () => + Download.createReadStream().then(result => { + if (result === null) { + return Nothing + } else { + return Just(result) + } + }) diff --git a/src/Playwright/Event.js b/src/Playwright/Event.js index 4a25055..23f1828 100644 --- a/src/Playwright/Event.js +++ b/src/Playwright/Event.js @@ -1,13 +1,7 @@ /* global exports */ -exports.onForeign = function (obj) { - return function (eventName) { - return function (effCallback) { - return function () { - obj.on(eventName, function (argument) { - effCallback(argument)(); - }); - }; - }; - }; -}; +export const onForeign = (obj) => (eventName) => (effCallback) => () => { + obj.on(eventName, (argument) => { + effCallback(argument)() + }) +} diff --git a/src/Playwright/Internal.js b/src/Playwright/Internal.js index 82ca986..df0f500 100644 --- a/src/Playwright/Internal.js +++ b/src/Playwright/Internal.js @@ -2,7 +2,7 @@ /** * @param {string} property - method to call on object - * @param {number} n - number of (curried) arguments + * @param {number} argsCount - number of (curried) arguments * @param {effectRunnerWrapper} effectRunnerWrapper - a function to overrride * effect runner with. `toAffE` for `Aff`, `identity` for `Effect`. * @@ -19,54 +19,33 @@ * effectfulGetter('close', 0, identity); */ function effectfulGetter (property, argsCount, effectRunnerWrapper) { - var args = []; - return function (object) { - function effectRunner () { - return object[property].apply(object, args); + function consume(arg, args, counter) { + const argsNew = [ ...args, arg ]; + + if (counter === 0) { + const [ object, ...rest ] = argsNew; + + return effectRunnerWrapper(() => object[property].apply(object, rest)) + } else { + return (a) => consume(a, argsNew, counter - 1) } + } - var affectRunner = effectRunnerWrapper(effectRunner); - - function chooseNext () { - return argsCount > 0 ? argsConsumer : affectRunner; - } - - function argsConsumer (arg) { - if (argsCount == 0) { - return affectRunner; - } else { - args.push(arg); - argsCount--; - return chooseNext(); - } - } - - return chooseNext(); - }; + return (object) => consume(object, [], argsCount) } function identity (x) { - return x; + return x; } -exports.unsafeEffCall = function (method) { - return function (argsCount) { - return effectfulGetter(method, argsCount, identity); - }; -}; - -exports.unsafeAffCall = function (toAffE) { - return function (method) { - return function (argsCount) { - return effectfulGetter(method, argsCount, toAffE); - }; - }; -}; - -exports.effProp = function (prop) { - return function (object) { - return function () { - return object[prop]; - }; - }; +export function unsafeEffCall(method) { + return argsCount => effectfulGetter(method, argsCount, identity); } + +export function unsafeAffCall(toAffE) { + return method => argsCount => effectfulGetter(method, argsCount, toAffE); +} + +export function effProp(prop) { + return object => () => object[prop]; +} \ No newline at end of file diff --git a/src/Playwright/JSHandle.js b/src/Playwright/JSHandle.js index 3afa5b8..6661f4a 100644 --- a/src/Playwright/JSHandle.js +++ b/src/Playwright/JSHandle.js @@ -1,17 +1,11 @@ /* global exports */ -exports.getProperties_ = function (insert) { - return function (emptyMap) { - return function (jsHandle) { - return function () { - return jsHandle.getProperties().then(function (props) { - var acc = emptyMap; - props.entries().forEach(function (pair) { - acc = insert(pair[0])(pair[1])(acc); - }); - return acc; - }); - }; - }; - }; -}; +export function getProperties_(insert) { + return emptyMap => jsHandle => () => jsHandle.getProperties().then(props => { + let acc = emptyMap; + props.entries().forEach(pair => { + acc = insert(pair[0])(pair[1])(acc); + }); + return acc; + }); +} diff --git a/src/Playwright/Options.purs b/src/Playwright/Options.purs index 381a615..918997a 100644 --- a/src/Playwright/Options.purs +++ b/src/Playwright/Options.purs @@ -3,13 +3,27 @@ module Playwright.Options where import Playwright.Data import Data.String.Regex (Regex) +import Data.Time.Duration (Milliseconds(..)) import Foreign (Foreign) import Foreign.Object (Object) import Literals.Null (Null) import Untagged.Union (UndefinedOr, type (|+|)) +import Playwright.Types (Cookie) type Opt a = UndefinedOr a +type FocusOptions = + { strict :: Opt Boolean + , timeout :: Opt Number + } + +type FillOptions = + { force :: Opt Boolean + , noWaitAfter :: Opt Boolean + , strict :: Opt Boolean + , timeout :: Opt Number + } + type LaunchOptions = { headless :: Opt Boolean , executablePath :: Opt String @@ -22,10 +36,17 @@ type LaunchOptions = , handleSIGINT :: Opt Boolean , handleSIGTERM :: Opt Boolean , handleSIGHUP :: Opt Boolean - , timeout :: Opt Number + , timeout :: Opt Milliseconds , env :: Opt (Object String) , devtools :: Opt Boolean , slowMo :: Opt Number + , storageState :: Opt { cookies :: Array Cookie } + } + +type ConnectOptions = + { headers :: Opt (Object String) + , slowMo :: Opt Number + , timeout :: Opt Number } type ProxyOptions = @@ -40,11 +61,11 @@ type ScreenshotOptions = , "type" :: Opt ScreenshotType , quality :: Opt Number , omitBackground :: Opt Boolean - , timeout :: Opt Number + , timeout :: Opt Milliseconds } type GotoOptions = - { timeout :: Opt Int + { timeout :: Opt Milliseconds , waitUntil :: Opt WaitUntil , referer :: Opt String } @@ -57,7 +78,7 @@ type NewpageOptions = } type GoOptions = - { timeout :: Opt Int + { timeout :: Opt Milliseconds , waitUntil :: Opt WaitUntil } @@ -68,11 +89,11 @@ type HoverOptions = } type InnerHTMLOptions = - { timeout :: Opt Number + { timeout :: Opt Milliseconds } type InnerTextOptions = - { timeout :: Opt Number + { timeout :: Opt Milliseconds } type KeyboardPressOptions = @@ -92,7 +113,7 @@ type ClickOptions = , modifiers :: Opt (Array Modifier) , force :: Opt Boolean , noWaitAfter :: Opt Boolean - , timeout :: Opt Int + , timeout :: Opt Milliseconds } type MouseClickOptions = @@ -116,31 +137,31 @@ type MouseMoveOptions = } type WaitForNavigationOptions = - { timeout :: Opt Int + { timeout :: Opt Milliseconds , url :: Opt (String |+| Regex |+| URL -> Boolean) , waitUntil :: Opt WaitUntil } type WaitForRequestOptions = - { timeout :: Opt Int + { timeout :: Opt Milliseconds } type WaitForResponseOptions = - { timeout :: Opt Int + { timeout :: Opt Milliseconds } type WaitForSelectorOptions = { state :: Opt ElementState - , timeout :: Opt Int + , timeout :: Opt Milliseconds } type WaitForFunctionOptions = { polling :: Opt (Int |+| Raf) - , timeout :: Opt Int + , timeout :: Opt Milliseconds } type WaitForLoadStateOptions = - { timeout :: Opt Int + { timeout :: Opt Milliseconds } type Margin = @@ -168,5 +189,5 @@ type PdfOptions = type SetFilesOptions = { noWaitAfter :: Opt Boolean - , timeout :: Opt Int + , timeout :: Opt Milliseconds } diff --git a/src/Playwright/Response.js b/src/Playwright/Response.js index fc28676..7a3d455 100644 --- a/src/Playwright/Response.js +++ b/src/Playwright/Response.js @@ -1,17 +1,10 @@ /* global exports */ -exports.finished_ = function (Nothing) { - return function (Just) { - return function (Response) { - return function () { - return Response.finished().then(function (result) { - if (result === null) { - return Nothing; - } else { - return Just(result); - } - }); - }; - }; - }; -}; +export const finished_ = Nothing => Just => Response => () => + Response.finished().then((result) => { + if (result === null) { + return Nothing + } else { + return Just(result) + } + }) diff --git a/src/Playwright/Types.purs b/src/Playwright/Types.purs new file mode 100644 index 0000000..26945b4 --- /dev/null +++ b/src/Playwright/Types.purs @@ -0,0 +1,14 @@ +module Playwright.Types where + +import Playwright.Data (SameSite) + +type Cookie = + { name :: String + , value :: String + , domain :: String + , path :: String + , expires :: Number + , httpOnly :: Boolean + , secure :: Boolean + , sameSite :: SameSite + } diff --git a/test/Main.purs b/test/Main.purs index 4b545ec..b7118ee 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -3,6 +3,7 @@ module Test.Main where import Control.Monad.Except (runExcept) import Data.Either (isLeft) import Data.Maybe (Maybe(..)) +import Data.Time.Duration (Milliseconds(..)) import Effect (Effect) import Effect.Aff (launchAff_, try) import Effect.Class (liftEffect) @@ -13,6 +14,7 @@ import Node.Encoding as Encoding import Node.FS.Aff as FS import Node.Stream as Stream import Playwright +import Node.EventEmitter (on_) import Playwright.ConsoleMessage as ConsoleMessage import Playwright.Dialog as Dialog import Playwright.Download as Download @@ -78,7 +80,7 @@ main = runTest do withBrowserPage hello \page -> do void $ waitForSelector page (Selector "body") {} - res <- try $ waitForSelector page (Selector "nonexistent") { timeout: 100 } + res <- try $ waitForSelector page (Selector "nonexistent") { timeout: Milliseconds 100.0 } Assert.assert "waitForSelector fails when no element" $ isLeft res test "waitForFunction" do @@ -89,7 +91,7 @@ main = runTest do void $ waitForFunction page "document.body.textContent.includes('uniqstring')" - { timeout: 5000, polling: 100 } + { timeout: Milliseconds 5000.0, polling: 100 } suite "FFI" do test "exposeBinding" do withBrowserPage hello \page -> do @@ -151,19 +153,22 @@ main = runTest do case mbStream of Nothing -> Assert.assert "Unable to get stream" false Just stream -> do - liftEffect $ Stream.onDataString stream Encoding.UTF8 $ \string -> do + liftEffect $ Stream.setEncoding stream Encoding.UTF8 + liftEffect $ stream # on_ Stream.dataHStr \string -> do Ref.write (Just string) downloadRef void $ evaluate page """ - function download(filename, text) { - var element = document.createElement('a'); - element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); - element.setAttribute('download', filename); - document.body.appendChild(element); - element.click(); - document.body.removeChild(element); + { + function download(filename, text) { + var element = document.createElement('a'); + element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); + element.setAttribute('download', filename); + document.body.appendChild(element); + element.click(); + document.body.removeChild(element); + } + download("hello.txt","hiiii"); } - download("hello.txt","hiiii"); """ waitForTimeout page 100 downloadContent <- liftEffect $ Ref.read downloadRef diff --git a/test/TestUtils.js b/test/TestUtils.js index e74b5e8..9887aa4 100644 --- a/test/TestUtils.js +++ b/test/TestUtils.js @@ -1,5 +1,5 @@ /* global exports __dirname */ -exports.cwd = process.cwd(); +export const cwd = process.cwd(); -exports.isNull = function (sth) { return sth === null; }; +export const isNull = sth => sth === null;