Call Firefox helper functions from JS

一笑奈何 提交于 2021-01-29 07:39:56

问题


Firefox Web Console offers a screenshot helper function:

:screenshot --selector '#element-id' --dpr 1

Probably a silly question, but is it possible to call this function from JavaScript at my website? Say, I have some button and it calls this:

function downloadScreenshot()
{
    if(navigator.userAgent.toLowerCase().indexOf('firefox') === -1)
    { alert("Firefox-only"); return; }

    eval(":screenshot --selector '#element-id' --dpr 1");
}

If I try to run this I naturally get SyntaxError: expected expression, got ':'.

So is there some way to call Firefox Web Console API (or whatever) from JS and "tell" it to execute the screenshot command?

Firefox Developer Edition 63.0b10 (64-bit).

I reckon, it is not possible. One of the reasons would be that "malicious" scripts at websites could spam your disc with screenshots taken every millisecond.


回答1:


You can't. Those helper functions are executed in a totally different context then a web page, with totally different privileges. Here the source code: https://searchfox.org/mozilla-central/source/devtools/shared/screenshot/save.js

So from a web page, you don't have access to them.

The only way to have a similar functionality, is create your own add-on that take the screenshot. Then, from your website, you can check if the add-on is installed, and send to it the command to take the screenshot.



来源:https://stackoverflow.com/questions/52608159/call-firefox-helper-functions-from-js

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