Mutation Observer – Chrome extension

Bonjour à tous,

Je suis en train de développer une extension pour Chrome dans le cadre d’une projet de fin d’étude en cybersécurité. Cet extension a pour but de scanner des sites internet et détecter les vulnérabilités potentielles.
Ce projet est réalisé en Vue.JS3
Côté client je tente de réaliser une lecture du DOM pour détecter les modifications éventuelles.
Nous utilisons les mutation Observer

Donc pour les sachants nous avons :

  • Une partie Options
  • Une partie DevTools
  • Une partie Popup
  • Une partie contentScripts

Nous lançons un mutation Observer dans le script de contenu de façon à récupérer le site sur lequel se trouve l’utilisateur, hors pour certains sites, l’extension récupére son propre DOM et je ne comprend pas pourquoi.

Par exemple ici sur https://test.fr la mutation fonctionne bien.
Mutation work

Mais ici sur un site crée pour détecter une DOM XSS fait à la mano ça ne fonctionne pas.
Mutation doesn’t work


import {
    createApp
} from 'vue';
import App from './views/App.vue';
import {
    setupApp
} from '~/logic/common-setup';
import store from '~/store';

(() => {
    var _a;

    const initialize = () => {
        console.log("Initializing...");

        const observer = new MutationObserver(async (mutationsList) => {
            try {
                console.log("Running observer");
                for (let mutation of mutationsList) {
                    switch (mutation.type) {
                        case 'childList':
                            for (let node of mutation.addedNodes) {
                                if (node.tagName === 'SCRIPT' && node.src.startsWith('moz-extension://')) {
                                    return;
                                }
                                // if (node.parentNode && node.parentNode.shadowRoot && node.parentNode.id === 'app-container') {
                                //     continue;
                                // }
                                if (node.nodeType === Node.TEXT_NODE && !node.data.trim()) {
                                    return;
                                }
                                await handleNodeAdded(node);
                            }
                            break;
                        case 'attributes':
                            await handleAttributeModified(mutation.target, mutation.attributeName);
                            break;
                        case 'characterData':
                            if (mutation.target.nodeType === Node.TEXT_NODE && !mutation.target.data.trim()) {
                                return;
                            }
                            await handleCharacterDataModified(mutation.target);
                            break;
                    }
                }
            } catch (error) {
                console.error('Error in observer:', error);
            }
        });

        observer.observe(document.documentElement, {
            childList: true,
            subtree: true,
            attributes: true,
            characterData: true
        });

        const container = document.createElement('div');
        container.id = 'app-container';
        const root = document.createElement('div');
        const styleEl = document.createElement('link');
        const shadowDOM = ((_a = container.attachShadow) === null || _a === void 0 ? void 0 : _a.call(container, {
            mode: 'open'
        })) || container;
        styleEl.setAttribute('rel', 'stylesheet');
        styleEl.setAttribute('href', browser.runtime.getURL('dist/contentScripts/style.css'));
        shadowDOM.appendChild(styleEl);
        shadowDOM.appendChild(root);
        document.body.appendChild(container);
        const app = createApp(App);

        app.use(store);
        setupApp(app);
        app.mount(root);

        store.dispatch('initializeAuthState');

        chrome.runtime.onMessage.addListener((message) => {
            console.log('Content Script: Message received:', message);
            if (message.action === 'setAuthState') {
                store.commit('setAuthState', message.payload);
            } else if (message.action === 'clearAuthState') {
                store.commit('clearAuthState');
            }
        });

        console.info('[WebPionneer] Content script initialized!');
    };

    window.addEventListener('DOMContentLoaded', initialize);
    window.addEventListener('load', initialize);

    const startPolling = () => {
        setInterval(() => {
            console.log('Polling for changes...');
            document.querySelectorAll('your-selector-here').forEach(node => {
                handleNodeAdded(node);
            });
        }, 2000);
    };

    window.addEventListener('DOMContentLoaded', startPolling);
    window.addEventListener('load', startPolling);

    async function handleNodeAdded(node) {
        console.log('Node added:', node);
        await new Promise(resolve => setTimeout(resolve, 1000));
        console.log('Async operation for added node completed');
    }

    async function handleAttributeModified(target, attributeName) {
        console.log('Attribute modified:', target, 'Attribute name:', attributeName);
        await new Promise(resolve => setTimeout(resolve, 1000));
        console.log('Async operation for attribute modification completed');
    }

    async function handleCharacterDataModified(target) {
        console.log('Character data modified:', target);
        await new Promise(resolve => setTimeout(resolve, 1000));
        console.log('Async operation for character data modification completed');
    }
})();

Merci à ceux qui sauront m’apporter une réponse ????

New contributor

Maeyx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật