DEV Community

Blueticks
Blueticks

Posted on

My script typed 4,953 characters into an editor and produced a text I could not publish

I automate my own publishing. A script opens a draft, types the title, types the body, and I check
the result before anything goes out. Last night it failed three times in a row, and each failure
looked like a success from a different angle.

First failure: the title landed, the body did not

The script reported the title matched exactly, character for character. The body came back empty.

My first instinct was that my reading was broken rather than my writing, which was half right. I had
kept a reference to the body element from before typing, and a rich editor re-renders constantly, so
the handle could have been pointing at a detached node. I re-read with a fresh query. The body was
genuinely empty.

The re-read did surface something else: there were two editable regions on the page, not one, and my
selector took the first. That was not the cause, but it was a real ambiguity sitting in my code.

Eliminating the obvious cause

The same script had worked an hour earlier on a short test sentence. Two things differed: the length
of the text, and the delay between keystrokes.

So I changed one of them. Same text, delay raised from 11 milliseconds to 20. Same failure.

That eliminated cadence, and elimination is what pointed at the real cause, which I would not have
guessed: the title. My test sentence had a 25 character title that fits on one line. The real title
is 97 characters and wraps onto three. Typing the title changed the layout, and the body moved.
My click was aimed at coordinates measured before the title existed, so it landed nowhere useful.

Measure the target after every action that can reflow the page. I had written that rule for other
people's forms and not applied it to my own.

Second failure: the body landed, and it was wrong

With the click fixed, the text went in. The script checked the character count: 4,836 against 4,953
expected. I explained the difference by the markdown syntax being consumed on conversion, decided it
was fine, and moved on.

It was not fine. My source files are hard wrapped at about a hundred characters, and my typing
routine sends every newline as an Enter key. Inside a paragraph, that creates a new paragraph.

The source has 30 paragraphs. The editor held 94 blocks. The character count was correct and the
document was mangled.

I found it by accident, reading the last line and seeing two words fused together where a wrap had
been. Then I counted blocks, which is the check I should have written in the first place.

A count of characters tells you almost nothing about structure. If you are pushing a document into
an editor, compare the number of blocks to the number of paragraphs in the source, and compare the
number of links to the number of links you expect. Those two numbers would have caught this in a
second.

What actually worked

Not typing. One synthetic paste event carrying text/html.

I converted the markdown myself: joined the wrapped lines inside each paragraph, turned ## into
h2, turned link syntax into anchors. Then dispatched a single paste event with that HTML on the
editable element.

Result: 30 blocks for 30 paragraphs, 6 headings, and 2 real links. The typing route had produced 94
blocks and zero links, because markdown links are not converted as you type, and neither is a bare
URL. That last detail matters more than it sounds: a text whose only link to my own site is inert is
a text that fails my own publication rule.

The pattern in all three

Every failure produced a measurement that said success.

The title matched exactly, and the body was empty. The character count was nearly right, and the
structure was destroyed. The click hit the correct element, verified by identity, and the element
was in the wrong place because the page had moved.

In each case the fix was not a better tool but a better question. Not "did the text arrive" but "how
many blocks and how many links". Not "is this the right element" but "is it still where I measured
it".

Disclosure

I build BlueTicks for Gmail, a Chrome and Firefox extension that shows WhatsApp style ticks in your
Gmail sent list, one tick sent and two blue ticks opened. It costs 4 dollars a year, and the free
tier covers 30 emails a month. The publishing automation above exists to distribute writing about
it, and it spends a good share of its time proving that its own reports are optimistic. You can find
it at blueticks.io.

A check that can only report success is not a check.

Top comments (0)