@@ -57,6 +57,30 @@ const API_BASE = process.env.SCREENITY_API_BASE_URL;
5757const CLOUD_FEATURES_ENABLED =
5858 process . env . SCREENITY_ENABLE_CLOUD_FEATURES === "true" ;
5959
60+ const ensureAudioOffscreen = async ( ) => {
61+ if ( ! chrome . offscreen ) return false ;
62+ try {
63+ const contexts = await chrome . runtime . getContexts ( { } ) ;
64+ const audioUrl = chrome . runtime . getURL ( "audiooffscreen.html" ) ;
65+ const hasAudioOffscreen = contexts . some (
66+ ( context ) =>
67+ context . contextType === "OFFSCREEN_DOCUMENT" &&
68+ context . documentUrl === audioUrl
69+ ) ;
70+ if ( ! hasAudioOffscreen ) {
71+ await chrome . offscreen . createDocument ( {
72+ url : "audiooffscreen.html" ,
73+ reasons : [ "AUDIO_PLAYBACK" ] ,
74+ justification : "Play short UI beep sounds." ,
75+ } ) ;
76+ }
77+ return true ;
78+ } catch ( error ) {
79+ console . warn ( "Failed to ensure audio offscreen document" , error ) ;
80+ return false ;
81+ }
82+ } ;
83+
6084let activeRecordingSession = null ;
6185let recordingTabListener = null ;
6286
@@ -953,6 +977,18 @@ export const setupHandlers = () => {
953977 registerMessage ( "clear-recording-alarm" , async ( ) => {
954978 await chrome . alarms . clear ( "recording-alarm" ) ;
955979 } ) ;
980+ registerMessage ( "get-tab-id" , ( message , sender , sendResponse ) => {
981+ sendResponse ( { tabId : sender ?. tab ?. id ?? null } ) ;
982+ return true ;
983+ } ) ;
984+ registerMessage ( "play-beep" , async ( message , sender , sendResponse ) => {
985+ const ok = await ensureAudioOffscreen ( ) ;
986+ if ( ok ) {
987+ chrome . runtime . sendMessage ( { type : "play-beep-offscreen" } ) ;
988+ }
989+ if ( sendResponse ) sendResponse ( { ok } ) ;
990+ return true ;
991+ } ) ;
956992 registerMessage ( "refresh-auth" , async ( ) => {
957993 if ( ! CLOUD_FEATURES_ENABLED )
958994 return { success : false , message : "Cloud features disabled" } ;
0 commit comments