mutation-observers

to set MutationObserver, How to inject javascript before page-loading using Selenium

左心房为你撑大大i 提交于 2019-11-29 03:56:57
问题 I'm trying to set MutationObserver for observing page mutation while loading. In order to do that, MutationObserver should be configured before page loading. With selenium-chromedriver, couldn't find the way to inject JS for such purpose. I know chrome extension can do that but extensions won't work on headless mode. That's the problem. 回答1: It's possible via the DevTool API by calling Page.addScriptToEvaluateOnNewDocument from selenium import webdriver from selenium.webdriver.remote

How do you get a mutation observer to detect a value change of a textarea?

a 夏天 提交于 2019-11-28 12:12:05
I have seen mutation observers used to obtain the properties of doms when they are modified such as with the google chrome developer tools. I can't, however, find how to call a function when the text within a textarea changes due to a user typing or pasting. In my code, as the user types the callbacks don't get called, even with all the observe options set to true. What is the code for this? The mutation observers listen for changes of the DOM. The current state of form elements, however, is not reflected by the DOM. For example, create an input element input without setting the value

Manually resizing an element doesn't fire a mutation observer in Chrome

ε祈祈猫儿з 提交于 2019-11-28 04:37:27
问题 I have a DIV with style resize: both and then I set a MutationObserver that listens for changes in attributes. mutObs = new MutationObserver(function () { console.log('Hello'); }); elem = document.getElementById('aDiv'); mutObs.observe(elem, { attributes: true }); elem.style.width = '300px'; //this fires the observer callback as expected I made a fiddle: http://jsfiddle.net/2NQQu/2/ In Chrome (I tested Chrome 31) the callback is not fired when you resize the DIV with the mouse. In Firefox it

Can jQuery selectors be used with DOM mutation observers?

一曲冷凌霜 提交于 2019-11-28 03:34:32
HTML5 includes a concept of "mutation observers" to monitor changes to the browser's DOM. Your observer callback will be passed data which looks a lot like DOM tree snippets. I don't know if they are exactly this or how they work really. But when you are writing code to interact with a 3rd party site over which you have no control, say with a Greasemonkey script or Google Chrome user script, you have to inspect the tree of elements passed in to find which information is relevant to you. This is much simpler with selectors, just like working with any DOM, than walking the tree manually,

Detecting class change without setInterval

泄露秘密 提交于 2019-11-28 02:39:42
问题 I have a div that has additional classes added to it programmatically. How can I detect the class name change without using this setInterval implementation? setInterval(function() { var elem = document.getElementsByClassName('original')[0]; if (elem.classList.contains("added")) { detected(); } }, 5500); MutationObserver? 回答1: You can use a mutation observer. It's quite widely supported nowadays. var e = document.getElementById('test') var observer = new MutationObserver(function (event) {

'observe' on 'MutationObserver': parameter 1 is not of type 'Node'

笑着哭i 提交于 2019-11-28 00:42:56
I am creating a Chrome extension and trying to include a small text beside the SEND button of the gMail compose box. I am using a MutationObserver to know when the compose box window appears. I am doing this by observing an element with class no since the compose box element is created as child of this element (class no ). When the user clicks on the compose button and the compose box window appears, then I place an element beside the SEND button using the .after() method. SEND button class name is .gU.Up . These are the real class names of gMail and pretty weird too. Below is the code I am

Watch for element creation in greasemonkey script?

故事扮演 提交于 2019-11-27 23:07:55
I need to be notified when an element with class 'nav' is created as the document is loading. Googling I found MutationObservers and thought they would be perfect, but I can't seem to get it working. // ==UserScript== // @name ii-shortcuts // @namespace https://github.com/RedHatter // @include * // @version 1 // @run-at document-start // ==/UserScript== var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.target.getAttribute('class') == 'nav') GM_log('nav creation'); }); }); observer.observe(document, {subtree: true, attributes: true,

Can jQuery selectors be used with DOM mutation observers?

时间秒杀一切 提交于 2019-11-27 05:07:24
问题 HTML5 includes a concept of "mutation observers" to monitor changes to the browser's DOM. Your observer callback will be passed data which looks a lot like DOM tree snippets. I don't know if they are exactly this or how they work really. But when you are writing code to interact with a 3rd party site over which you have no control, say with a Greasemonkey script or Google Chrome user script, you have to inspect the tree of elements passed in to find which information is relevant to you. This

Watch for element creation in greasemonkey script?

只谈情不闲聊 提交于 2019-11-27 04:39:48
问题 I need to be notified when an element with class 'nav' is created as the document is loading. Googling I found MutationObservers and thought they would be perfect, but I can't seem to get it working. // ==UserScript== // @name ii-shortcuts // @namespace https://github.com/RedHatter // @include * // @version 1 // @run-at document-start // ==/UserScript== var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.target.getAttribute('class') ==

How to change the HTML content as it's loading on the page

我与影子孤独终老i 提交于 2019-11-27 02:15:35
I do A/B Testing on our site and I do most of my work is in a JS file that is loaded at the top of the page before anything else is rendered but after jQuery has loaded which comes in handy at times. Taking a very simple example of changing an H1 tag, I would normally inject a style in the head to set the H1 opacity to 0 and then on DOMContentLoaded, I would manipulate the H1 contents and then set the opacity to 1. The reason for this is to avoid a flash of the old content before the change takes place - hiding the whole object is more graceful on the eye. I've started to look at the