How to launch html using Chrome at “--allow-file-access-from-files” mode?

前端 未结 11 1625
我寻月下人不归
我寻月下人不归 2020-11-21 23:12

I have the same situation with HERE

And to solve this problem I have to launch html file using Chrome at \"--allow-file-access-from-files\" mode. I tried next steps

相关标签:
11条回答
  • 2020-11-21 23:59

    That flag is dangerous!! Leaves your file system open for access. Documents originating from anywhere, local or web, should not, by default, have any access to local file:/// resources.

    Much better solution is to run a little http server locally.

    --- For Windows ---

    The easiest is to install http-server globally using node's package manager:

    npm install -g http-server

    Then simply run http-server in any of your project directories:

    Eg. d:\my_project> http-server

    Starting up http-server, serving ./
    Available on:
     http:169.254.116.232:8080
     http:192.168.88.1:8080
     http:192.168.0.7:8080
     http:127.0.0.1:8080
    Hit CTRL-C to stop the server
    

    Or as prusswan suggested, you can also install Python under windows, and follow the instructions below.

    --- For Linux ---

    Since Python is usually available in most linux distributions, just run python -m SimpleHTTPServer in your project directory, and you can load your page on http://localhost:8000

    In Python 3 the SimpleHTTPServer module has been merged into http.server, so the new command is python3 -m http.server.

    Easy, and no security risk of accidentally leaving your browser open vulnerable.

    0 讨论(0)
  • 2020-11-22 00:02
    REM Kill all existing instance of chrome 
    taskkill /F /IM chrome.exe /T
    REM directory path where chrome.exe is located
    set chromeLocation="C:\Program Files (x86)\Google\Chrome\Application"
    cd %chromeLocation%
    cd c:
    start chrome.exe --allow-file-access-from-files
    

    save above lines as .bat file

    0 讨论(0)
  • 2020-11-22 00:04

    Depending on the file which will be put into filesystem, as long as that file is not a malware, then that would be safe.

    But don't worry to write/read file(s) to File System directory, cause you can tighten that directory security (include it's inheritance) by give a proper access right and security restriction. eg: read/write/modify.

    By default, File System, Local Storage, and Storage directory are located on "\Users[Current User]\AppData\Local\Google\Chrome\User Data\Default" directory.

    However you can customize it by using "--user-data-dir" flag.

    And this is a sample:

    "C:\Program Files (x86)\Google\Application\chrome.exe" --user-data-dir="C:\Chrome_Data\OO7" --allow-file-access-from-files
    

    Hope this helps anyone.

    0 讨论(0)
  • 2020-11-22 00:05

    Search for the path of your Chrome executable and then, on your cmd, try :

    > "C:\PathTo\Chrome.exe" --allow-file-access-from-files
    

    Source

    EDIT : As I see on your question, don't forget that Windows is a little bit similar to Unix, so when you type "chrome ...", cmd will search for Chrome in the PATH, but in general the Chrome folder isn't on the PATH. Also, you don't specify an extension for your executable... So if you move to Chrome's folder, this command will probably work too :

    > .\chrome.exe --allow-file-access-from-files
    
    0 讨论(0)
  • 2020-11-22 00:10

    Quit (force quit) all instances of chrome. Otherwise the below command will not work.

    open -a "Google Chrome" --args --allow-file-access-from-files
    

    Executing this command in terminal will open Chrome regardless of where it is installed.

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