Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
891 views
in Technique[技术] by (71.8m points)

twitter - Headless Chrome does not execute JS

I'm running a headless chrome to take screenshots of tweets via the oEmbed API.

Downloading the tweets and creating the HTML works fine, but the embedded JS does not run, which causes the tweets to be unstyled in the screenshot.

When I fetch the created HTML file and open it in my Firefox, the JS is loaded, executed and styles the tweet perfectly.

Is this a problem with headless chrome, twitter itself or something else?

My CLI command looks like this:

google-chrome -headless -screenshot=' + filename_image + ' ' + msg.filename + ' -force-device-scale-factor=2 -virtual-time-budget=20000 -window-size=516,3000 --disable-gpu

This is from the node-red script which prepares the CLI command which is then passed to the bash via an "exec"-node.

Edit #1: To make it clear: The screenshot works in general, but the result is unstyled, as no external script is loaded and executed.

I've also tried to disable ufw to check whether it's a problem with the firewall. It's not. The problem persists, even with disabled firewall.

Edit #2: I added the --disable-gpu flag to get rid of this error message, which was also written to the console. Sadly that didn't change anything about the end-result.

Edit #3: Back on this. Tried running the same exact command through a PHP script. Everything works fine, tweets are styled perfectly. Doesn't make this any less strange.

question from:https://stackoverflow.com/questions/66068276/headless-chrome-does-not-execute-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...