问题
I've installed webshot package and meteor webshot smart package from: https://github.com/TimHeckel/meteor-webshot
In the directory pacages/webshot/lib/webshot.js there is definition of WEBSHOT object. In the default meteor application I want to use this object to get the snapshot as show in the second step from the link above:
Template.hello.events({
'click input' : function () {
var _image = "myscreenshot.png";
var _res = WEBSHOT.snap("http://google.com", "public/exports~/" + _image, {
screenSize: {
width: 300
, height: 300
}
});
}
});
When I click on the button I have an exception: Uncaught ReferenceError: WEBSHOT is not defined.
Command:
meteor list
show webshot package, where do I need to include this package to get this working?
回答1:
The WEBSHOT
object is available only on the server side. See this line in package.js.
To use it, you need to create a method on the server with Meteor.methods
, use WEBSHOT
inside it and then call this method from your event handler.
回答2:
Hubert OG is right, this package is server-side only.
However, it hasn't been updated in 5 months, so it looks like it's not up to date with the latest "linker" of Meteor which is a feature that appeared in 0.6.5 if I remember well.
You need to git clone the package in your local packages directory. (you may need to "meteor remove" the previous package and "meteor add" the new one). Then modify package.js so that it looks like this :
Package.on_use(function (api) {
api.add_files("lib/webshot.js", "server");
api.export("WEBSHOT","server");
});
From Meteor 0.6.5, you need to explicitly specify which symbols from the package are exported to the global namespace, because the package code is executed inside a closure.
回答3:
I had the same problem so I added a new Meteor wrapper using the latest version of node-webshot: https://atmospherejs.com/bryanmorgan/webshot.
You should be able to get it working using:
meteor add bryanmorgan:webshot
And then 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/19745715/how-to-use-webshot-with-meteor