Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Paul Kinlan
Paul Kinlan

Posted on • Originally published atpaul.kinlan.me on

     

domcurl: curl + JavaScript

For a long time I’ve been thinking about what the future of the web looks like when we go past what we know as the traditional web browser. I called thisThe Headless Web and I wanted to answer was “What if everything was powered by ‘The Web’, but you never saw a browser?“. Specifically I believe that if you have access to a full browser, but no visible to “chrome” then there is a huge opportunity for a new set of services.

Using the browser as a service is an incredible opportunity. It allows us to take the declarative HTML and combine it with the developer defined procedural execution of JavaScript and run deep analysis on the content.

Running a browser on the server will allow us to more easily build services which parse data that is generated dynamically, it will allow us to more easily us run our own logic against the logic in a page (form fill as an example) and I believe that it will open up the ability to more effectively run actions against data embedded on the page.

It’s taken a while, but I think we are getting there.

I’m enamored byPuppeteer. Puppeteer is a JavaScript library that sits on top of the Chrome Dev Tools protocol and it allows you to automate and script the Chrome browser.

My day-to-day work involves a lot of debugging web servers and ensuring. Like many developers I usecurl to make requests to a web server and check the response. It’s an amazing utility, however in today’s world many developers are building sites that are built using a lot of JavaScript and this makes it impossible to inspect the complete response.

I decided to create a cUrl-like utility for fetching a resource and running the JavaScript on the page calleddomcurl.

domcurl is asmall NodeJS applicationthat uses Puppeteer and can be installed by issuing the following command:npm
i domcurl
. Like thecurl command you can issue a simpledomcurl [url] to fetch the resource and run the JS on the page.

It doesn’t replicate all ofcurl, but it is quite featureful with the following features.

  • Specify a url to fetch. i.e,domcurl [url]
  • Inspect the response headers with-v. i.e,domcurl -v [url]
  • Set cookies with-b i.e,domcurl [url] -b "test=hello;Domain=airhorner.com; HttpOnly;" -b "hello=world; Domain=airhorner.com;HttpOnly;"
  • Add custom headers using the-H argument.
  • Manually set the STDOUT with-o and STDERR with--stderr

I’m finding it quite useful eventhough it can’t stream the results likecurlcan because it has to wait for the CSS and JS to be downloaded and executed.

I also took the liberty to add a couple of extra features that are specific to JavaScript and Chrome.

  • Output a Chrome Dev Tools trace file (including screens hots.)domcurl --urlhttps://example.com --trace test.json
  • Include it as a JavaScript module if you have the need to integrate it into any of your existing applications.
const {domcurl} = require('domcurl');domcurl(`https://paul.kinlan.me/`, {});
Enter fullscreen modeExit fullscreen mode

Whilst this tool is more of a demo than a full service, I thinkThe Headless Web is maturing and tools like Puppeteer and others are going to help us realize the continued power of the web. We just need to build for it.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Lead for Chrome Developer Relations at Google.Happy Shipper of lots of Cool things and proud of our team! :)
  • Location
    Liverpool / London
  • Work
    Senior Staff Developer Advocate, Lead Chrome DevRel at Google
  • Joined

More fromPaul Kinlan

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp