Separate session for each window

烂漫一生 提交于 2019-12-03 05:40:39

问题


I am trying to create an extension where each window of chrome has its own session. We used incognito earlier, but the problem is that while the main window and the incognito window have separate sessions, the session is shared between the various incognito windows.

Is there any way of configuring chrome to use a separate session every time an incognito window is opened?


回答1:


Your goal will be start a Chrome instance with a new user data directory. The cookies will be isolated in each instance. In the extension to implement a way to reach the same goal as this command on cmd:

chrome.exe --user-data-dir="C:\temp\user1"



回答2:


I had a similar problem where i want to use google chrome for browsing and debugging for work and chrome is pretty original when it comes to sessions. I wrote this small batch script to duplicate the default profile, clear session information and then use the new profile. Old duplicate profiles are also cleared before the new ones are created. The result is a new session with all the old profile stuff.

@echo off

rem folder prefix for the new profile folder
set folderNameStart=profile_

rem generate and format the date creating the new folder name
For /f "tokens=1-6 delims=/ " %%a in ('date /t') do (set mydate=%%c%%b%%a)
For /f "tokens=1-2 delims=/:" %%a in ('time /t') do (set mytime=%%a%%b)
set folderName=%folderNameStart%%mydate%%mytime%%random%

rem set the profile path and the folder destination as well as the directory to 
delete
set profilePath="C:\Documents and 
Settings\%USERNAME%\AppData\Local\Google\Chrome\User Data\Default"
set profileDestination="C:\Documents and 
Settings\%USERNAME%\AppData\Local\Google\Chrome\User Data\"%folderName%
set profileLocation="C:\Documents and 
Settings\%USERNAME%\AppData\Local\Google\Chrome\User Data\"

rem iterate through directory and delete all the existing profile folders
CD %profileLocation%
echo %profileLocation%
for /D /r %%G in ("%folderNameStart%*") do rmdir /q /s "%%G"

rem this will copy the old profile directory 
echo D | xcopy %profilePath% %profileDestination%

rem delete the session storage and its contents if its exist
rmdir /q /s "C:\Documents and Settings\%USERNAME%\AppData\Local\Google\Chrome\User 
Data\%folderName%\Session Storage"


rem start google chrome with the new profile folder
start "Chrome" "C:\Program Files\Google\Chrome\Application\chrome.exe" --profile-directory="%folderName%"


来源:https://stackoverflow.com/questions/13301965/separate-session-for-each-window

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