Hello,
my twitter bot was working until May 23 when it started tweeting the same image over and over again…
project name is cellular-botomata
in create-img.js it creates a image using p5.js on a canvas
var cnv = createCanvas(510, 510);
cnv.id('ca-canvas');
then on the node side, in server.js, it runs puppeteer, takes a screenshot and then stashes the png in the tmp directory. the following code is how puppeteer knows to take a screenshot of the canvas element.
var imgBuff = await screenshotDOMElement({
path: 'tmp/desire.png',
selector: 'canvas',
padding: 0
})
Then it waits for puppeteer to evaluate the page - code is from screenshotDOMElement():
const rect = await page.evaluate(selector => {
const element = document.querySelector(selector);
if (!element)
return null;
const {x, y, width, height} = element.getBoundingClientRect();
return {left: x, top: y, width, height, id: element.id};
}, selector);
if (!rect)
throw Error(`Could not find element that matches selector: ${selector}.`);
/app/server.js:49 is the throw Error message.
cron-job.org is making successful GET requests
create-img.js is generating a new img each time I click “show live” or go to https://cellular-botomata.glitch.me/.
I deleted desire.png from the tmp directory and now nothing gets tweeted because server.js is not writing a desire.png file into the tmp directory.
Node is throwing the following error messages over and over:
(node:536) UnhandledPromiseRejectionWarning: Error: Could not find element that matches selector: canvas.
at screenshotDOMElement (/app/server.js:49:13)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:536) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().
I used a mix-in from someone else to get puppeteer to work, but, as I said, this was working a week ago, not sure if I’m having the error because I’m not handling async issues – no catch blocks, no .catch() - still trying to figure out how to code these properly – or if something changed with puppeteer in the last week or so and I need to update that code.
Any suggestions/directions will be helpful.