11console . log ( '백그라운드 기능' ) ;
2- chrome . runtime . onMessage . addListener ( ( message , _sender , sendResponse ) => {
3- if ( message . type === 'FETCH_OG_META' ) {
4- fetch ( message . url )
5- . then ( ( res ) => res . text ( ) )
6- . then ( ( html ) => {
7- const parser = new DOMParser ( ) ;
8- const doc = parser . parseFromString ( html , 'text/html' ) ;
9-
10- const getMeta = ( prop ) =>
11- doc
12- . querySelector ( `meta[property="${ prop } "]` )
13- ?. getAttribute ( 'content' ) || '' ;
14-
15- const makeAbsoluteUrl = ( base , img ) => {
16- try {
17- return img ? new URL ( img , base ) . href : '' ;
18- } catch {
19- return img ;
20- }
21- } ;
22-
23- const image = getMeta ( 'og:image' ) ;
24-
25- sendResponse ( {
26- title : getMeta ( 'og:title' ) ,
27- description : getMeta ( 'og:description' ) ,
28- siteName : getMeta ( 'og:site_name' ) ,
29- image : makeAbsoluteUrl ( message . url , image ) ,
30- url : getMeta ( 'og:url' ) || message . url ,
2+ chrome . runtime . onInstalled . addListener ( ( details ) => {
3+ if ( details . reason === 'install' ) {
4+ chrome . identity . getProfileUserInfo ( function ( info ) {
5+ chrome . storage . local . set ( { 'userEmail' : info . email } , ( ) => {
6+ console . log ( info . email ) ;
317 } ) ;
32- } )
33- . catch ( ( err ) => {
34- console . error ( 'OG fetch 실패:' , err ) ;
35- sendResponse ( null ) ;
36- } ) ;
37- return true ; // async 응답
8+ setTimeout ( ( ) => {
9+ chrome . tabs . create ( {
10+ url : `http://localhost:5173/onboarding?email= ${ info . email } ` ,
11+ } ) ;
12+ } , 1000 ) ;
13+ } ) ;
3814 }
3915} ) ;
16+
17+
18+ chrome . runtime . onMessage . addListener ( ( message ) => {
19+ if ( message . type === 'SET_TOKEN' ) {
20+ chrome . storage . local . set ( { 'token' : message . token } , ( ) => {
21+ console . log ( 'Token saved!' , message . token ) ;
22+ } ) ;
23+ }
24+ } ) ;
0 commit comments