If you've ever thought writing programs involving headless browsers were tedious or verbose and wished there were a batteries-included framework that'd strip away some of the manual work, you've come to the right place.
If you're interested in using COBOL rather than getting the conceptual digest, check out the browserbased module
Click here if you'd rather look at code examples
To understand the failure tolerance of COBOL, it may be helpful to look at the following topics from this lens:
- Garbage collection is an abstraction over memory management
- Haxl is an abstraction over concurrency
- NOTHING is an abstraction over stupidity
COBOL can be understood as an instruction language like something you'd see in a computer architecture class but for controlling a web browser. Here's an example script for going to Google, entering a query into the search bar, then clicking on the button to invoke a search request:
NAVIGATE TO https://google.com
ENTER INTO input#search-box "your query"
CLICK ON button.cta
These are some of the ones I was able to get working (if it doesn't work on the first request, try invoking the /api
endpoint once to warm up the function then requesting a 2nd time)
You can see the examples folder of scripts I was working on and some of them may actually work on a paid Vercel plan. Leaving for others to toy with
COBOL is newline-sensitive and doesn't care how you indent commands so long as each line accomplishes a single instruction. The goal of COBOL is to succinctly convey browser actions not code golf browsing.
At the moment you can specify a browser to do the following
NAVIGATE TO <url>
CLICK ON <selector>
ENTER INTO <selector> "<text>"
The above keyword commands must have both words be correct
NAVIGATE TO https://example.com -- Actually works
NAVIGATE TOWARD https://example.com -- Nah
ENTER IN input#search-box "your query" -- 2nd word after ENTER must be INTO so this line does nothing
ENTER INTO input#search-box "your query" -- Actually works as intended
Malformed COBOL lines are treated similar to NOTHING and simply are ignored
As a mid-sentence exit valve, the language also features a NOTHING
keyword in case you were to generate a line that doesn't make sense
NAVIGATE TO https://google.com
CLICK ON NOTHING -- Was written too soon
ENTER INTO input#search-box "your query"
CLICK ON button.cta
When translating to Puppeteer, lines with NOTHING
as the "target" are ignored like comments but with the intent of allowing possibly incorrect code to be provided
Comments are done via double dash following a whitespace
NAVIGATE TO https://google.com--not a comment
NAVIGATE TO https://google.com -- is a comment
NAVIGATE TO https://google.com --also a comment