Why is it not possible to define non configurable properties in the global window object? - firefox-developer-edition

I get the following error in Firefox 52.0a2 (2017-01-06), when I try to set a non configurable property to the window object.
TypeError: Not allowed to define a non-configurable property on the WindowProxy object
However it's working in the latest Firefox release (50.1.0) without any problems. (btw, it's also working in Opera and Chrome)
Example code:
Object.defineProperty(window, 'test', {
enumerable: false,
configurable: false,
writable: false,
value: 'value'
});

Since Firefox 53 it's working, regardless of the build type.
More info: https://bugzilla.mozilla.org/show_bug.cgi?id=1329323

Related

Mouseover in cypress

I am a newbie in cypress and trying to create some basic scripts for my learning, Handling dropdown by clicking the elements is fine, but hovering on the element is not working in this case, I can see the required element is getting hovered but the sub-menu is not appearing.
it.only('Mouse hover using trigger ', () => {
cy.visit('https://www.puregrips.com/pages/custom-grips')
cy.contains("a", "Custom").trigger('mouseover')
})
You can use the cypress-real-events plugin and this worked with your webpage.
To install use the command:
npm i cypress-real-events
Then inside your cypress/support/index.{js,ts}, write:
import "cypress-real-events/support";
And in your code you can directly write:
cy.contains("a", "Custom").realHover('mouse')
Note: Since the above plugin uses Chrome DevTools Protocols to simulate native events, hence this will only work with Chromium-based browsers, so no firefox.
Things I tried that didn't work -
cy.contains("a", "Custom").trigger('mouseover')
cy.contains("a", "Custom").invoke('show')
Just try this, it should work:
cy.get('.locater').invoke('show').click({ force: true })
cy.get('[your selector]')
.eq(0).invoke('show')
.trigger('mouseenter')
.wait(1000)
.should('have.attr','your-selector','Active tooltip')
.trigger('mouseleave');
This worked for me for the above problem.
Issue:
Timed out retrying after 5000ms: cy.trigger() failed because this element is not visible: CUSTOM
This element <a.header__linklist-link.link--animated> is not visible because its parent <ul.header__linklist.list--unstyled.hidden-pocket.hidden-lap> has CSS property: display: none
it.only("Mouse hover using trigger ", () => {
cy.viewport(1440, 660); //setting viewport as site is responsive web design
cy.visit("https://www.puregrips.com/pages/custom-grips"); //visit url
//used within to get parent and children to get the desired web-element
//and used invoke("show") to show the hidden elements
cy.get(".header__linklist").within(() => {
cy.get("li").contains("CUSTOM").invoke("show");
});
});
Added final screenshot:

Remove oscpu property from from window.navigator

If you are using FireFox, navigator has a property oscpu.
The property can be easily changed by appending general.oscpu.override value in about:config.
But, this option is present only in FireFox and does not exist in any other browser. This allows a 100% certainty to determine the type of browser.
Conventional means can not remove it. Whatever happened that ( oscpu in navigator) would return false.
All this does not work:
delete navigator.oscpu;
'oscpu' in navigator; // true
navigator.oscpu = null;
'serviceWorker' in navigator; // true
navigator.oscpu === null; // false
Object.defineProperty(navigator, "oscpu", {
configurable: true,
value: undefined
});
'oscpu' in navigator; // true
navigator.oscpu === undefined; // true
Are there ways to remove this property from navigator? And indeed any other parameter. I am writing a Firefox Add-on SDK extension.
There are potential side effects of doing what you are wanting to accomplish. It would be helpful to know what your goals are in order to determine a good way to accomplish what you desire.
However, for what you have specifically requested, removing navigator.oscpu in the current scope, the following works:
//This specific code relies on navigator referring to the object which you want to
// modify. In an Add-on SDK extension, if navigator is _actually_ the object you need
// to modify to accomplish what you desire will depend on the scope you are in and
// what object you have set the variable navigator to refer to.
delete navigator.__proto__.oscpu;
console.log(navigator.oscpu); // undefined
'oscpu' in navigator // false
Note that you will need to do this within every context/scope in which you desire for it to have effect. In general, this means that you will need to inject a content script into every page and frame in which you wish this to be the case. It also means that you should take care to only do it in the context/scopes in which you are wanting it to be seen by whatever JavaScript you are attempting to spoof (i.e. within the scope of page scripts, not in the scope of code running with Chrome privileges.).

How to change the theme in an Ace editor?

I've been trying to add syntax highlighting to my web app and found ace. However, after working at the solution provided in the documentation, I am still unable to change the editor theme. Does anyone know how to go about this?
So far I've just initialized the element with the following code
var editor = ace.edit("editor");
editor.getSession().setUseWrapMode(true);
editor.setHighlightActiveLine(true);
editor.setShowPrintMargin(false);
editor.setTheme('ace-builds-master/theme/tomorrow_night.css');
editor.getSession().setMode("ace/mode/javascript");
In the build mode argument to setTheme() is not a path but an id of the theme so you need to call
.setTheme('ace/theme/tomorrow_night') instead
Note that you also can set all the options in one call using
editor.setOptions({
useWrapMode: true,
highlightActiveLine: true,
showPrintMargin: false,
theme: 'ace/theme/tomorrow_night',
mode: 'ace/mode/javascript'
})
or in newer version of ace pass object with options to ace.edit
var editor = ace.edit("editor"{
useWrapMode: true,
...
})

firefox startScroll and sendAsyncMessage

In recent version of Firefox 31+ the startScroll(e) function was changed and should be called with startScroll(scrolldir, screenX, screenY)
Diff of the change:
https://hg.mozilla.org/integration/mozilla-inbound/diff/cc298e4b0f47/toolkit/content/widgets/browser.xml
Before the change I could initiate startScroll manually from my classic bootstrap.js extension with:
aWindow.gBrowser.selectedBrowser.startScroll(e);
I've received a tip on mozilla IRC channel to use sendAsyncMessage "Autoscroll:Start" so I tried various combinations of
aWindow.gBrowser.selectedBrowser.startScroll("NSEW", e.screenX, e.screenY);
aWindow.gBrowser.selectedBrowser.messageManager.sendAsyncMessage("Autoscroll:Start", {scrolldir:"NSEW", screenX:e.screenX, screenY:e.screenY});
but nothing works.
Bare minimum boostrap.js extension of my problem can be seen on http://pastebin.com/azv1jePt
Does anybody have any idea how to manually start autoscroll in the newer version of Firefox directly from bootstrap.js extension, without using any chrome scripts?
Thanks
Senicar
What worked for me was to simulate a middle button mousedown event from a frame script (no need to call startScroll nor sendAsyncMessage):
content.document.documentElement.dispatchEvent(new content.MouseEvent("mousedown", {
view: content,
bubbles: true,
cancelable: true,
button: 1,
screenX: /* anEvent.screenX */,
screenY: /* anEvent.screenY */
}));
Hope this helps

Dojo Xhr: Result Content is Not Appearing until there is a mouse click anywhere on page

i'm building an offline application with Dojo 1.7, using Dojo RDD, generating forms dynamically and storing them in cache.
now every time when i fetch something through ajax i have to remove dojo registry because dojo binds widgets by id if i dont clear registry it will cause problem in parsing dojo widgets because their ids already exist in widget registry, but when i clear registry every time it causes another problem. everything works fine but the result content only appear when clicking anywhere on page. same as described in:
Dynamic Elements are not appearing in IE8 until there is a mouse click
but, in this case this problem is with Chrome.
and the solution provided in above url doesn't work in this case.
exp:
//in some cases registry is destructor is not called.
dojo.xhrGet({
url: serverUrl,
content: {},
load: function(result) {
//destroying widget registry.(before any parsing)
dijit.registry._destroyAll();
// here is html processing.
},
error: function(error) {
utility.handleException(error);
}
});

Resources