用临时用户数据目录启动Chrome,关闭安全检查等(解决Cross origin requests are only supported for HTTP?)

时间:2022-11-10 03:51:56

Cross origin requests are only supported for HTTP?

参考:https://www.zhihu.com/question/20948649

批处理:

start_chrome_with_tmp_userdata.bat

 @echo off
pushd %~dp0
set TMP_USERDATA="%CD%/tmp_userdata"
set TMP_URL="%~1"
if %TMP_URL%=="" goto :help
echo Starting chrome...
"%appdata%\..\Local\Google\Chrome\Application\chrome.exe" --allow-file-access-from-files --disable-web-security --user-data-dir=%TMP_USERDATA% %TMP_URL%
echo Cleannig tmp dir...
ping 127.1 -n 1 >nul
rd /s /q %TMP_USERDATA% >nul
goto :end
:help
set TMP_CMD=%~n0%~x0
echo Usage:
echo [1] %TMP_CMD% http://www.baidu.com
echo [2] call %TMP_CMD% http://www.baidu.com
echo.
echo Press any key to exit...
pause>nul
:end
popd

调用例子1:

@echo off
call start_chrome_with_tmp_userdata.bat "%CD%\video-js-6.6.2/examples/index.html"

调用例子2:

C:\> start_chrome_with_tmp_userdata.bat http://www.baidu.com

Python3 启动http

start_python_web.bat

 @echo off
pushd %~dp0
set port=%~1
if "%port%"=="" goto :help
set process_title=%~n0,%port%
echo Kill last process...
taskkill /f /fi "WINDOWTITLE eq %process_title%" > nul
echo Starting python http.server %port%...
start "%process_title%" python -m http.server %port%
goto :end
:help
set TMP_CMD=%~n0%~x0
echo Usage:
echo set port=8081
echo call %TMP_CMD% %%port%%
echo start "" http://localhost:%%port%%
echo.
echo Press any key to exit...
pause>nul
:end
popd

例子:

 @echo off
set port=8081
call start_python_web.bat %port%
ping 127.1 -n 1 >nul
echo Starting demo...
start "" http://localhost:%port%/video-js-6.6.2/examples/simple-embed/h265.html
start "" http://localhost:%port%/libde265.js/demo/libde265_DEMO.html