我需要自动化HTML 5视频播放器页面及其缩略图的屏幕截图,但在查看一些比较流行的无头浏览器(如 PhantomJS )后,它们不支持HTML 5视频。
>phantomjs examples\features.js
Detected features (using Modernizr 2.0.6):
Supported:
touch
generatedcontent
fontface
flexbox
canvas
canvastext
postmessage
websqldatabase
hashchange
history
draganddrop
websockets
rgba
hsla
multiplebgs
backgroundsize
borderimage
borderradius
boxshadow
textshadow
opacity
cssanimations
csscolumns
cssgradients
cssreflections
csstransforms
csstransitions
localstorage
sessionstorage
webworkers
applicationcache
svg
inlinesvg
smil
svgclippaths
Not supported:
csstransforms3d
webgl
geolocation
indexeddb
video
audio
请注意,上面不支持HTML 5视频,哪种轻量级无头浏览器支持支持HTML 5视频?
答案 0 :(得分:1)
基于the documentation,SlimerJS可以播放HTML5视频和音频(并提供截图):
由于SlimerJS是在Firefox之上执行的,它支持最近在Firefox中实现的所有HTML5标准,包括音频,视频,WebGL等。
SlimerJS中的网页呈现与Firefox中的呈现完全相同。
您可以继续caniuse.com查看Firefox支持的HTML5功能列表,您可以在SlimerJS加载的网页中使用。
据说也支持Flash,但屏幕截图中没有Flash内容:
如果安装了Flash插件,SlimerJS可以加载Flash内容(虽然在截图时无法看到插件的渲染)。
答案 1 :(得分:1)
有一个解决方案但它不是轻量级。(虽然它很快)现在你可以运行带有无头选项的Firefox 。这里有一些代码如何使用Selenium 。
options = new FirefoxOptions();
options.addArguments("--headless"); // This will make Firefox to run in headless mode.
System.setProperty("webdriver.gecko.driver", "lib/firefox/geckodriver.exe");
FirefoxProfile profile = new FirefoxProfile();
FirefoxBinary binary = new FirefoxBinary(new File("lib/firefox/firefox.exe"));
options.setBinary(binary);
options.setProfile(profile);
driver = new FirefoxDriver(options);
或您可以构建PanthomJS以支持HTML5 。请遵循此https://github.com/ariya/phantomjs/issues/10839#issuecomment-331457673