Javascript 更换铬合金&x27;通过chrome扩展使用inject_脚本实现WebAPI函数

Javascript 更换铬合金&x27;通过chrome扩展使用inject_脚本实现WebAPI函数,javascript,google-chrome-extension,navigator,content-script,webauthn,Javascript,Google Chrome Extension,Navigator,Content Script,Webauthn,我正在使用chrome扩展替换navigator.credentials.create()和navigator.credentials.get()navigator.credentials.create()用于为第二因素身份验证注册“安全密钥”。我的替换脚本适用于Facebook和GitHub等网站,但不适用于Gmail、Twitter、Amazon AWS等网站。可能是什么问题?为什么这里有不一致之处 content\u script.ts const webauthnInject = do

我正在使用chrome扩展替换
navigator.credentials.create()
navigator.credentials.get()
navigator.credentials.create()
用于为第二因素身份验证注册“安全密钥”。我的替换脚本适用于Facebook和GitHub等网站,但不适用于Gmail、Twitter、Amazon AWS等网站。可能是什么问题?为什么这里有不一致之处

content\u script.ts

 const webauthnInject = document.createElement('script');
 webauthnInject.type = 'text/javascript';
 webauthnInject.src = 'chrome-extension://' + chrome.runtime.id + '/js/inject_webauthn.js';
 document.documentElement.appendChild(webauthnInject);
注入\u webauthn.ts

(() => {
cKeyCredentials.create = async (options: CredentialCreationOptions): Promise<Credential | null> => {//code}

cKeyCredentials.get = async (options: CredentialRequestOptions): Promise<Credential | null | any> => {//code}

Object.assign(navigator.credentials, cKeyCredentials);
})();
更新

这个问题很可能是因为wOxxOm和Kaido指出的新的动态iFrame。所以,我正在尝试使用mutationObserver

var observer = new MutationObserver(function (mutations) {
    mutations.forEach(function (mutation) {
        [].filter.call(mutation.addedNodes, function (node) {
            return node.nodeName == 'IFRAME';
        }).forEach(function (node) {
            node.addEventListener('load', function (e) {
                console.log('loaded', node.src);
            });
        });
    });
});
observer.observe(document.documentElement, { childList: true, subtree: true });
我在content_script.js中添加了上述观察者。它仍然没有检测到相关的新IFRAME

当我启动2FA时,将加载调用credentials.create APi的脚本。有没有办法找到为什么这里不调用我的注入代码函数?

这些站点可能在其服务人员内部使用API。扩展无法在那里运行。@wOxxOm谢谢您的评论。是否有办法查看服务人员,以确保他们是否在使用服务人员?有没有办法用扩展来替换服务人员返回的响应?我不太喜欢chrome扩展,但是这个脚本也会在iFrame中自我注入吗?避免脚本小子的一个常见技巧是从一个新的iframe调用敏感方法,它将有一个干净的作用域。FWIW,有一种方法可以消除iframe技巧:spoof Document.prototype.createElement in。最高级的选项是spoof createElement,您尝试过吗?除此之外,您还必须对站点代码进行反向工程。Devtools还有一个多文件搜索工具Ctrl-Shift-F。这些站点可能在其服务人员内部使用API。扩展无法在那里运行。@wOxxOm谢谢您的评论。是否有办法查看服务人员,以确保他们是否在使用服务人员?有没有办法用扩展来替换服务人员返回的响应?我不太喜欢chrome扩展,但是这个脚本也会在iFrame中自我注入吗?避免脚本小子的一个常见技巧是从一个新的iframe调用敏感方法,它将有一个干净的作用域。FWIW,有一种方法可以消除iframe技巧:spoof Document.prototype.createElement in。最高级的选项是spoof createElement,您尝试过吗?除此之外,您还必须对站点代码进行反向工程。Devtools还有一个多文件搜索工具Ctrl-Shift-F。
var observer = new MutationObserver(function (mutations) {
    mutations.forEach(function (mutation) {
        [].filter.call(mutation.addedNodes, function (node) {
            return node.nodeName == 'IFRAME';
        }).forEach(function (node) {
            node.addEventListener('load', function (e) {
                console.log('loaded', node.src);
            });
        });
    });
});
observer.observe(document.documentElement, { childList: true, subtree: true });