Getting session.defaultSession in webview preload script

Hello,

I am currently trying to block content from a webview using session.defaultSession.webRequest.onBeforeRequest inside a preload script.

However, I can’t seem to get the webview’s session object. I tried simply attaching my blocker or using document.addEventListener('DOMContentLoaded', function(event) { to wait for the DOM content to load but I can’t get it.
I always get the error:

Uncaught ReferenceError: session is not defined

Is there a way I can access the session object from preload? Or is there a way I can inject my blocker into the page otherwise?