{"id":17692899,"url":"https://github.com/arsalan0c/cdp-hs","last_synced_at":"2025-05-12T20:05:49.283Z","repository":{"id":41196161,"uuid":"489557116","full_name":"arsalan0c/cdp-hs","owner":"arsalan0c","description":"Haskell library for the Chrome DevTools Protocol","archived":false,"fork":false,"pushed_at":"2023-12-27T22:16:42.000Z","size":1539,"stargazers_count":9,"open_issues_count":3,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-03-15T04:11:51.659Z","etag":null,"topics":["chrome","chrome-devtools-protocol","haskell"],"latest_commit_sha":null,"homepage":"https://hackage.haskell.org/package/cdp","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arsalan0c.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-07T03:27:15.000Z","updated_at":"2023-11-19T13:35:59.000Z","dependencies_parsed_at":"2024-10-24T15:29:45.283Z","dependency_job_id":"26a80a6c-3f21-47ed-8fd2-0c4824167682","html_url":"https://github.com/arsalan0c/cdp-hs","commit_stats":{"total_commits":63,"total_committers":6,"mean_commits":10.5,"dds":0.4285714285714286,"last_synced_commit":"b93bd551fe2dc27f490956b94be92e37a3787c9b"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arsalan0c%2Fcdp-hs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arsalan0c%2Fcdp-hs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arsalan0c%2Fcdp-hs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arsalan0c%2Fcdp-hs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arsalan0c","download_url":"https://codeload.github.com/arsalan0c/cdp-hs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222716186,"owners_count":17027697,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chrome","chrome-devtools-protocol","haskell"],"created_at":"2024-10-24T13:07:29.409Z","updated_at":"2024-11-02T13:04:37.730Z","avatar_url":"https://github.com/arsalan0c.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![build](https://github.com/arsalan0c/cdp-hs/actions/workflows/build.yaml/badge.svg)](https://github.com/arsalan0c/cdp-hs/actions/workflows/build.yaml)\n# cdp-hs\n\nA Haskell library for the [Chrome Devtools Protocol (CDP)](https://chromedevtools.github.io/devtools-protocol/), generated from the protocol's definition files.\n\n## Example usage\n\nEnsure Chrome is running with the remote debugging port enabled:\n\n```\n$ chromium --headless --remote-debugging-port=9222 https://wikipedia.com\n```\n\nThe following program can be used to print a page to PDF, with Base64 encoded data being read in chunks:\n\n```hs\n{-# LANGUAGE OverloadedStrings   #-}\n\nmodule Main where\n\nimport Data.Maybe\nimport Data.Default\nimport qualified Data.ByteString.Base64.Lazy as Base64\nimport qualified Data.ByteString.Lazy as BL\nimport qualified Data.Text as T\nimport qualified Data.Text.Lazy as TL\nimport qualified Data.Text.Lazy.Encoding as TL\n\nimport qualified CDP as CDP\n\nmain :: IO ()\nmain = CDP.runClient def printPDF\n\nprintPDF :: CDP.Handle -\u003e IO ()\nprintPDF handle = do\n    -- send the Page.printToPDF command\n    r \u003c- CDP.sendCommandWait handle $ CDP.pPagePrintToPDF\n        { CDP.pPagePrintToPDFTransferMode = Just CDP.PPagePrintToPDFTransferModeReturnAsStream\n        }\n\n    -- obtain stream handle from which to read pdf data\n    let streamHandle = fromJust . CDP.pagePrintToPDFStream $ r\n\n    -- read pdf data 24000 bytes at a time\n    let params = CDP.PIORead streamHandle Nothing $ Just 24000\n    reads \u003c- whileTrue (not . CDP.iOReadEof) $ CDP.sendCommandWait handle params\n    let dat = map decode reads\n    BL.writeFile \"mypdf.pdf\" $ BL.concat dat\n\ndecode :: CDP.IORead -\u003e BL.ByteString\ndecode ior = if (CDP.iOReadBase64Encoded ior == Just True)\n    then Base64.decodeLenient lbs\n    else lbs\n  where\n    lbs = TL.encodeUtf8 . TL.fromStrict . CDP.iOReadData $ ior\n\nwhileTrue :: Monad m =\u003e (a -\u003e Bool) -\u003e m a -\u003e m [a]\nwhileTrue f act = do\n    a \u003c- act\n    if f a\n        then pure . (a :) =\u003c\u003c whileTrue f act\n        else pure [a]\n\n```\n\nMore examples can be found in `examples`.\n\n## Generating the CDP library\n\n```\ncabal run cdp-gen\n```\n\n## Current state\n\n[Project board](https://github.com/users/arsalan0c/projects/1)\n\nCommands and events for all non-deprecated domains are supported.\n\nSessions can also be created with a target (such as a tab), which can be used to restrict the scope of commands and events for the target.\nSee `examples/sessions.hs` for example usage.\n## Contributing\n\nPRs are welcome! If you would like to discuss changes or have any feedback, feel free to open an [issue](https://github.com/arsalan0c/cdp-hs/issues).\n\n\n## Acknowledgements\n\nThis began as a [Summer of Haskell](https://summer.haskell.org) / [GSoC](https://summerofcode.withgoogle.com) project. Albert Krewinkel ([@tarleb](https://github.com/tarleb)), Jasper Van der Jeugt ([@jaspervdj](https://github.com/jaspervdj)) and Romain Lesur ([@RLesur](https://github.com/rlesur)) provided valuable feedback and support which along with raising the library's quality, has made this all the more enjoyable to work on.\n\n## References\n\n- https://jaspervdj.be/posts/2013-09-01-controlling-chromium-in-haskell.html\n- https://www.jsonrpc.org/specification\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farsalan0c%2Fcdp-hs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farsalan0c%2Fcdp-hs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farsalan0c%2Fcdp-hs/lists"}