meteor-webshot is not working to take a screenshot and save it on the server

为君一笑 提交于 2019-12-11 09:52:58

问题


On the server I would like to take a screenshot of an external link and save it to the server in a folder.

I am trying to use the package webshot for meteor:

https://github.com/TimHeckel/meteor-webshot

But it is not working. I installed the package using mrt add webshot. The package installed successfully. According to this stackoverflow: How to use webshot with meteor

I was able to edit the package.js file for webshot to export WEBSHOT variable server side like so:

Package.on_use(function (api) {
    api.add_files("lib/webshot.js", "server");
    api.export("WEBSHOT","server"); // This was the new line added to export WEBSHOT
});

This is the code I am calling server side to take the webshot:

Meteor.methods 
  post: (postAttributes) ->
    console.log postAttributes.url // 'http://yahoo.com'
    _image = "myscreenshot.png";
    _res = WEBSHOT.snap(postAttributes.url, "public/exports~/" + _image,
      screenSize:
        width: 300
        height: 300
    )

I have a directory in the public folder called exports~ and when I run my code no image is saved to the directory, and I do not get any errors. I have no clue what is happening!

Since I have setup my meteor to be able to install npm packages server side, I also tried to use the npm webshot package by installing using the regular old npm install webshot.

Then I tried using webshot = Meteor.require('webshot') but it never worked because I could not start the app as it kept crashing with error like:

node_modules/webshot/node_modules/phantomjs/node_modules/request/node_modules/node-uuid/test/test.html:1: bad formatting in HTML template........

So I cannot use webshot the regular npm using Meteor.require. But I finally got it working when using the meteor smart package as long as I add

api.export("WEBSHOT","server");

to the package.js file for webshot. But still it does not actually take the screenshot. Please someone clue me in!


回答1:


I have traced your question from meteor-phantomjs git-hub page. I've got a same problem with you, to use meteor-phantomjs and now I realize we need to include phantoms directly to the project, because meteor-phantomjs just only wrapping an environment path and even it uses phantomjs-sun package. (I don't know the differences)

So I'm trying to use phantomjs directly and here's the sequence.

1.install phantomjs to Server 2.add exact phantomjs npm package version to packages.json file in Meteor project 3.use Meteor.require('phantomjs') on the Meteor source

But there's another problem also, because node phantomjs npm package seems that just execute the phantom-script.js file on the child_process and that's all! So I think we have to excute and control the data as we wanted.

There might be some misunderstood because I'm kind of newbie in Node & Meteor, but I hope this could be helpful. Thanks.




回答2:


I had the same problem so I added a new Meteor wrapper (https://atmospherejs.com/bryanmorgan/webshot) using the latest version of node-webshot (0.15.4).You should be able to use:

meteor add bryanmorgan:webshot

And the same API as node-webshot:

webshot("http://google.com", "/tmp/google.png", function (err) {
    // screenshot saved to /tmp/google.png
});


来源:https://stackoverflow.com/questions/24441963/meteor-webshot-is-not-working-to-take-a-screenshot-and-save-it-on-the-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!