0

I'm using "run_at": "document_end" but the website on which it runs simply overload when a booking quota opens. Means in 8/10 cases for first 5 minutes the content script does not get invoked. It could be that a js file does not get loaded and take long time to load

What I want is that even if the DOM loading has failed or still being loaded I want to start content script immediately if a "#label1" element is found on the page.

How to achieve it?

Right now I've changed run_at to docment_start with this logic in the content script:

var sidbegin = setInterval(function () {

        console.log('script started');

        if (document.getElementById('label1')) //is label1 there?
            {
                $(document).ready(function () {
                    $("#label1").before('<button id="fillall">Fill All</button>');

                    $("#fillall").click(function(){
                        main_func();
                        return false;
                    });
                    clearInterval(sidbegin);
                });

            }

    }, 200);

Manifest File

{
    "name": "inv b Autofill",
    "options_page": "options.html",
    "description": "Autofiller and clicker for inv b",
    "version": "1.3",
    "icons": {
        "16": "icons/logo16.png",
        "48": "icons/logo48.png",
        "128": "icons/logo128.png"
    },
    "permissions": [
        "tabs",  "notifications", "cookies", "history", "browsingData", "activeTab", "storage", "webRequest", "webRequestBlocking", "http://*/*", "https://*/*"
    ],
    "background": {
        "scripts": [
            "js/lz-string.min.js",
            "client_server_common.js",
            "common.js",
            "background.js"
        ],
        "persistent": true
    },
    "browser_action": {
        "default_title": "Change the v details",
        "default_popup": "options.html"
    },
    "content_security_policy": "script-src 'self'; object-src 'self'",
    "manifest_version": 2,
    "content_scripts": [
        {
            "run_at": "document_end",
            "all_frames": true,
            "matches": ["*://inv-b.nic.in/*", "http://inv-b.nic.in/", "http://45.79.8.5/*"],
            "css": ["jqueryui/jquery-ui.css", "jqueryui/jquery-ui.css", "js/slidenavi/sidenavi-right.css","main.css", "jqueryui/jquery-ui.css", "js/bootstrap-switch-master/dist/css/bootstrap3/bootstrap-switch.min.css"],
            "js": ["jquery-2.1.4.min.js", "jqueryui/jquery-ui.min.js", "js/jquery.cookie.js", "jqueryui/jquery-ui.min.js","js/slidenavi/SideNavi.js","js/cryptojs/rollups/aes.js", "client_server_common.js", "user-selections.js",
                "jquery.countdown.min.js", "js/bootstrap-switch-master/dist/js/bootstrap-switch.min.js", "js/cryptojs/rollups/md5.js", "js/ocrad.js", "common.js",
                "myscript.js"
            ]
        },
        {
            "run_at": "document_start",
            "all_frames": true,
            "matches": ["*://inv-b.nic.in/*", "http://inv-b.nic.in/", "http://45.79.8.5/*"],
            "css": ["jqueryui/jquery-ui.css", "main.css", "jqueryui/jquery-ui.css", "js/bootstrap-switch-master/dist/css/bootstrap3/bootstrap-switch.min.css"],
            "js": ["jquery-2.1.4.min.js", "jqueryui/jquery-ui.min.js", "js/jquery.cookie.js", "js/cryptojs/rollups/aes.js", "client_server_common.js", "user-selections.js",
                "jquery.countdown.min.js", "js/bootstrap-switch-master/dist/js/bootstrap-switch.min.js", "js/cryptojs/rollups/md5.js", "js/ocrad.js", "common.js",
                "myscriptbeforedom.js"
            ]
        },
        {
            "run_at": "document_start",
            "all_frames": false,
            "matches": ["*://inv-b.nic.in/*", "http://inv-b.nic.in/", "http://45.79.8.5/*"],
            "js": ["client_server_common.js", "common.js", "injected/remove-alert.js"]
        }
    ],
    "web_accessible_resources": [
        "options.html", "terms.html", "resource/v/js/modernizr.js",
    ]


}
user5858
  • 1,082
  • 4
  • 39
  • 79
  • 1
    Without seeing the site and your manifest.json I can suggest only the obvious solution: simply remove `$(document).ready(function () {` as it doesn't make sense in the context. – wOxxOm Oct 01 '16 at 14:32
  • @wOxxOm so as the DOM is being downloaded will Jquery stick to it? – user5858 Oct 01 '16 at 17:00
  • 1
    jQuery sticks the moment it was executed at the start of content script injection. Also, if you need just the click functionality, there's no need to wait for the element: [on() vs live() click function on element that doesn't exist yet](//stackoverflow.com/q/15092578) – wOxxOm Oct 01 '16 at 17:08

0 Answers0