Separate session for each window

前端 未结 3 1905
萌比男神i
萌比男神i 2021-02-01 04:01

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 wi

3条回答
  •  走了就别回头了
    2021-02-01 04:38

    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%"
    

提交回复
热议问题