Skip to content

Commit

Permalink
feat: send session keepalive requests every 5 minutes
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemSBulgakov committed Jul 14, 2024
1 parent 9fd02dc commit bc522ef
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/entrypoints/content-script-moodle/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
injectSessionKeepalive,
redirectFromLogin,
refreshPageOnAutologin,
requestAutologinIfNeeded,
Expand All @@ -23,6 +24,7 @@ onMessage('AUTOLOGIN_FAILED', () => {
function main() {
sendMessage('MOODLE_LOAD')
requestAutologinIfNeeded()
injectSessionKeepalive()
}

main()
4 changes: 4 additions & 0 deletions src/entrypoints/content-script-moodle/session-keepalive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Touch session regularly to keep it alive
setInterval(() => {
require('core/ajax').call([{ methodname: 'core_session_touch', args: {} }])
}, 5 * 60 * 1000) // 5 minutes
7 changes: 7 additions & 0 deletions src/features/autologin/content-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,10 @@ export function showAutologinNotification() {
notification.remove()
}, 2000)
}

export function injectSessionKeepalive() {
const script = document.createElement('script')
script.type = 'text/javascript'
script.src = chrome.runtime.getURL('src/entrypoints/content-script-moodle/session-keepalive.js')
document.body.appendChild(script)
}
5 changes: 5 additions & 0 deletions src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export default defineManifest({
resources: ['icons/logo-16.png', 'icons/logo-32.png', 'icons/logo-48.png', 'icons/logo-128.png'],
matches: [],
},
{
// Injected into the moodle page to keep the session alive
resources: ['src/entrypoints/content-script-moodle/session-keepalive.js'],
matches: ['https://moodle.innopolis.university/*'],
},
],

permissions: [
Expand Down

0 comments on commit bc522ef

Please # to comment.