전체 정리 대상
항목 설명
Extensions/ 실제 확장 코드
Extension State/ 확장 상태 DB
IndexedDB/ 저장소 (indexedDB)
Local Storage/ localStorage 데이터
Service Worker/CacheStorage/ 백그라운드 캐시
Code Cache/js/ JS 실행 캐시
기본 사용자 프로필(Default)만 대상으로 합니다.
여러 사용자 프로필을 사용하는 경우, "Profile 1", "Profile 2" 등 디렉토리에 대해서도 동일하게 처리 가능.
import os
import shutil
import subprocess
import time
# 설정
EXTENSION_ID = "abcdefghijklmnopabcdefghijklmnop" # 실제 확장 ID로 바꾸세요
PROFILE = "Default" # Edge 프로필 이름 (보통은 "Default")
# 기본 경로 설정
local_app_data = os.environ['LOCALAPPDATA']
user_data_dir = os.path.join(local_app_data, "Microsoft", "Edge", "User Data", PROFILE)
# 삭제할 경로들 (확장 ID 기반)
target_dirs = {
"Extensions": os.path.join(user_data_dir, "Extensions", EXTENSION_ID),
"Extension State": os.path.join(user_data_dir, "Extension State"),
"IndexedDB": os.path.join(user_data_dir, "IndexedDB"),
"Local Storage": os.path.join(user_data_dir, "Local Storage"),
"Service Worker Cache": os.path.join(user_data_dir, "Service Worker", "CacheStorage"),
"Code Cache": os.path.join(user_data_dir, "Code Cache", "js"),
}
def kill_edge():
print("[*] Edge 종료 중...")
subprocess.run("taskkill /F /IM msedge.exe", shell=True, stdout=subprocess.DEVNULL)
def delete_by_extension_id(path, id):
deleted = False
if not os.path.exists(path):
return False
for root, dirs, files in os.walk(path):
for name in dirs + files:
if id in name:
full_path = os.path.join(root, name)
try:
if os.path.isdir(full_path):
shutil.rmtree(full_path)
else:
os.remove(full_path)
print(f"[+] 삭제됨: {full_path}")
deleted = True
except Exception as e:
print(f"[!] 삭제 실패: {full_path} ({e})")
return deleted
def clear_extension_data():
print(f"[*] 확장 프로그램 ID: {EXTENSION_ID} 관련 모든 저장 데이터 삭제 중...")
for label, path in target_dirs.items():
print(f"--- {label} ---")
if EXTENSION_ID in path and os.path.exists(path):
try:
shutil.rmtree(path)
print(f"[+] 전체 삭제됨: {path}")
except Exception as e:
print(f"[!] 삭제 실패: {path} ({e})")
else:
found = delete_by_extension_id(path, EXTENSION_ID)
if not found:
print(f"[-] 관련 항목 없음: {path}")
def restart_edge():
print("[*] Edge 재시작...")
subprocess.Popen("start msedge.exe", shell=True)
if __name__ == "__main__":
kill_edge()
time.sleep(2)
clear_extension_data()
restart_edge()
old
import os
import shutil
import subprocess
import time
# 설정
EXTENSION_ID = "abcdefghijklmnopabcdefghijklmnop" # 삭제 대상 확장 ID
PROFILE = "Default" # 사용자 프로필 이름 (보통은 "Default")
# 경로 설정
local_app_data = os.environ['LOCALAPPDATA']
base_dir = os.path.join(local_app_data, "Microsoft", "Edge", "User Data", PROFILE)
target_dirs = [
os.path.join(base_dir, "Extensions", EXTENSION_ID), # 확장 프로그램 코드
os.path.join(base_dir, "Extension State"), # 상태 정보 전체 (선택적 삭제)
os.path.join(base_dir, "Service Worker", "CacheStorage"), # 백그라운드 SW 캐시
os.path.join(base_dir, "Code Cache", "js"), # JS 실행 캐시 (선택적)
]
def kill_edge():
print("[*] Edge 종료 중...")
subprocess.run("taskkill /F /IM msedge.exe", shell=True, stdout=subprocess.DEVNULL)
def delete_extension_cache():
print(f"[*] 확장 프로그램 ID: {EXTENSION_ID} 관련 캐시 삭제 중...")
for path in target_dirs:
if not os.path.exists(path):
print(f"[-] 존재하지 않음: {path}")
continue
if EXTENSION_ID in path:
# 명시적으로 ID 포함된 경로만 삭제
try:
shutil.rmtree(path)
print(f"[+] 삭제됨: {path}")
except Exception as e:
print(f"[!] 삭제 실패: {path} ({e})")
else:
# 내부에서 해당 ID 관련 캐시 파일이 있는 경우 필터 삭제
deleted = False
for entry in os.listdir(path):
full_path = os.path.join(path, entry)
if EXTENSION_ID in entry:
try:
if os.path.isdir(full_path):
shutil.rmtree(full_path)
else:
os.remove(full_path)
print(f"[+] 삭제됨: {full_path}")
deleted = True
except Exception as e:
print(f"[!] 삭제 실패: {full_path} ({e})")
if not deleted:
print(f"[-] 해당 ID 관련 항목 없음: {path}")
def restart_edge():
print("[*] Edge 재시작...")
subprocess.Popen("start msedge.exe", shell=True)
if __name__ == "__main__":
kill_edge()
time.sleep(2)
delete_extension_cache()
restart_edge()
'배움의공간(學) > Python' 카테고리의 다른 글
오픈API 사용해보기 (0) | 2020.06.30 |
---|---|
파이썬 크롤러 (0) | 2020.03.18 |
A Visual Intro to NumPy and Data Representation (0) | 2019.08.07 |
수학공식 (0) | 2019.07.23 |
댓글