Browser Auto Select file through File Input Tag via Browser Extension

前端 未结 1 1488
粉色の甜心
粉色の甜心 2021-01-16 15:13

I want to auto select a file through
File input tag < input type=file > via java script ?

I know this is security issue and not allowed normally.

B

相关标签:
1条回答
  • 2021-01-16 16:14

    Firefox extensions are allowed to set input.value property so something like this will work:

    input.value = "c:\\autoexec.bat";
    input.form.submit();
    

    However, when using Add-on SDK a content script will likely not have the necessary privileges (needs to be tested). In this case one would need to use chrome authority and access the web page directly rather than via a content script.

    As to Chrome, extensions there don't have access to the file system - so the security restrictions that apply to web pages are applying to extensions as well. Allowing extensions to set the value of a file upload widget would be a security issue there. So I'm pretty sure that it isn't possible.

    0 讨论(0)
提交回复
热议问题