(function () {
    "use strict";

    function focusLockService() {
        var elementToInert = document.querySelector('#mainwrapper');

        function addInertAttribute() {
            elementToInert.setAttribute('inert', true);
        }

        function removeInertAttribute() {
            elementToInert.removeAttribute('inert');
        }

        var service = {
            addInertAttribute: addInertAttribute,
            removeInertAttribute: removeInertAttribute
        }

        return service;

    }
    
    angular.module("umbraco.services").factory("focusLockService", focusLockService);

})();

(function () {
    "use strict";

    function focusLockService($document) {
        var elementToInert = $document[0].querySelector('#mainwrapper');

        function addInertAttribute() {
            if (elementToInert) {
                elementToInert.setAttribute('inert', true);
            }
        }

        function removeInertAttribute() {
            if (elementToInert) {
                elementToInert.removeAttribute('inert');
            }
        }

        var service = {
            addInertAttribute: addInertAttribute,
            removeInertAttribute: removeInertAttribute
        }

        return service;

    }

    angular.module("umbraco.services").factory("focusLockService", focusLockService);

})();

Use $document and don't try to add or remove if the element is not found
Use $document and don't try to add or remove if the element is not found
