Webshot custom css

Webshot custom css

本文关键字:css custom Webshot      更新时间:2023-09-26

我试图将我的网站保存为使用WebShot与nodeJs的图像。在文档中,它说WebShot有customCSS选项,让应用自定义css样式的网页截图之前。我想使用该选项,但当我试图运行我的文件与节点它给了我一个错误: customCSS:'body { ^^^^^^^ SyntaxError: Unexpected token ILLEGAL

我的代码如下:
var options = {
  siteType: "html",
  //defaultWhiteBackground: true,
  customCSS:"body {
    background-color: #b0c4de;
}"
};
webshot(svgsrc,'graphy2.png',options,function(err) {
if(err) {
                console.log('error saving document', err)
            } else {
                console.log('The file was saved!');
            }
}); 

我可以保存图像没有问题,只是我找不到一种方法来应用自定义css保存图像之前,所以任何帮助将不胜感激。由于

试试这个(单引号,在一行中):

var options = {
  siteType: 'html',
  customCSS: 'body {background-color: #b0c4de;}'
}

参考:link和this

我发现我需要指定(例如):

 -webkit-justify-content
为:

justify-content

你也可以转义你的行

var options = {
  siteType: "html",
  //defaultWhiteBackground: true,
  customCSS:"body { '
    background-color: #b0c4de; '
}"
};