• Daum
  • |
  • 카페
  • |
  • 테이블
  • |
  • 메일
  • |
  • 카페앱 설치
 
카페정보
작심앱잼
 
 
 
카페 게시글
우리들의 이야기 Background
김강민 추천 0 조회 4 24.06.17 09:18 댓글 4
게시글 본문내용
 
다음검색
댓글
  • 작성자 24.06.17 09:48

    첫댓글 {
    "manifest_version": 3,
    "name": "Active Tab Tracker",
    "version": "1.0",
    "permissions": ["identity", "tabs", "activeTab", "scripting"],
    "background": {
    "service_worker": "background.js"
    },
    "oauth2": {
    "client_id": "701644259365-h3uc3q1f85c9g13o2f7j0ung9afuef8s.apps.googleusercontent.com",
    "scopes": ["https://www.googleapis.com/auth/userinfo.email"]
    },
    "action": {
    "default_popup": "popup.html"
    }
    }

  • 작성자 24.06.17 09:49

    function getGoogleAccountInfo(callback) {
    chrome.identity.getAuthToken({ interactive: true }, (token) => {
    if (chrome.runtime.lastError) {
    console.error(chrome.runtime.lastError);
    alert(`Failed to get Google account info: ${chrome.runtime.lastError.message}`);
    return;
    }

    fetch('https://www.googleapis.com/oauth2/v1/userinfo?alt=json', {
    headers: {
    'Authorization': `Bearer ${token}`
    }
    })
    .then(response => response.json())
    .then(data => {
    callback(data.email);
    })
    .catch(error => {
    console.error(error);
    alert(`Failed to ge

  • 작성자 24.06.17 09:49

    t Google account info: ${error.message}`);
    });
    });
    }

    // 활성화된 탭이 변경될 때 이벤트 처리
    chrome.tabs.onActivated.addListener((activeInfo) => {
    chrome.tabs.get(activeInfo.tabId, (tab) => {
    if (tab) {
    const tabInfo = {
    url: tab.url,
    title: tab.title
    };

    // 구글 계정 정보와 탭 정보를 alert로 표시
    getGoogleAccountInfo((email) => {
    chrome.scripting.executeScript({
    target: { tabId: activeInfo.tabId },
    func: showAlert,
    args: [tabInfo, email]
    });
    });
    }
    });
    });

    // 모든 탭 클릭을 감지하기 위해 탭 업데이트 이벤트 추가
    chrome.tabs.onUpdated.add

  • 작성자 24.06.17 09:49

    Listener((tabId, changeInfo, tab) => {
    if (changeInfo.status === 'complete' && tab.active) {
    const tabInfo = {
    url: tab.url,
    title: tab.title
    };

    // 구글 계정 정보와 탭 정보를 alert로 표시
    getGoogleAccountInfo((email) => {
    chrome.scripting.executeScript({
    target: { tabId: tabId },
    func: showAlert,
    args: [tabInfo, email]
    });
    });
    }
    });

    // alert를 띄우는 함수
    function showAlert(tabInfo, email) {
    alert(`URL: ${tabInfo.url}\nTitle: ${tabInfo.title}\nEmail: ${email}`);
    }

최신목록