How to find child nodes that match a selector with JavaScript
Direct child selection with querySelectorAll is awkward without :scope; :scope > ... targets only immediate descendants instead of every matching descendant.
How to access Chrome Devtools when running JavaScript tests via CLI
Running JavaScript tests from the CLI bypasses browser DevTools, so debugger statements are ignored. node --inspect-brk lets Chrome DevTools attach to Jest and pause execution.
Javascript: Avoid using innerHTML for unsafe arguments
Unsafe innerHTML use can introduce XSS when user content is inserted into HTML. textContent or text keeps values escaped for safe text updates.
Capybara: evaluate_script might freeze your browser
evaluate_script can freeze a browser window for about 10 seconds when it returns complex JavaScript objects; execute_script avoids the costly result conversion.
JavaScript Sentry: How to check if errors will be reported
Quickly verify that a JavaScript Sentry setup reports browser errors by triggering a deliberate exception in a click handler.
JavaScript: New Features in ES2021
ES2021 adds safer global string replacement, Promise.any(), logical assignment operators, numeric separators and WeakRef support in modern browsers.
Google Chrome now has a JavaScript bundle visualizer
Chrome’s Lighthouse adds a visualizer for JavaScript bundles, making large modules and unused bytes easier to spot when source maps are available.
Adding Jasmine JavaScript specs to a Webpack(er) project
Browser-based unit tests in a Rails app can run with Jasmine and Webpacker by separating test runner and spec packs; a /jasmine page makes the setup easy to open.
Chrome DevTools: DOM Breakpoints - Breakpoints on HTML Elements
DOM breakpoints in Chrome DevTools or Firefox Inspector help trace JavaScript that changes an element’s subtree, attributes, or removes it.
Bug in Chrome 56+ prevents filling in fields with slashes using selenium-webdriver/Capybara
Chrome 56+ can drop slashes when fill_in runs through Selenium and Capybara, breaking form input for paths and HTML strings; a JavaScript workaround updates the field directly.
Reading and writing cookies in JavaScript
Client-side cookies in JavaScript can be read and written through document.cookie, but values must be parsed and path and expiry must be set carefully.
Flexible overflow handling with CSS and JavaScript
Truncates one variable-length label while keeping a second label visible on the same line, with a JavaScript fallback for browsers without the needed layout.
High-level Javascript frameworks: Backbone vs. Ember vs. Knockout
High-level MV* JavaScript frameworks reduce DOM boilerplate with client-side rendering, routing, and data binding, but choosing between Backbone, Ember, and Knockout depends on style and needs.
Why your javascripts should be executed after the dom has been loaded
JavaScript that touches the DOM can run too early and fail before elements exist in the parsed tree. Waiting for DOM ready avoids timing bugs and missing nodes.
Guideline for moving from jQuery to vanilla JavaScript
Practical equivalents for common jQuery patterns in vanilla JavaScript, useful when modern browser support makes dependency-free code feasible.
Jasmine: Expecting objects as method invocation arguments
Jasmine spy assertions can match invocation arguments by type, partial object shape, or any value using jasmine.any(), jasmine.objectContaining(), and jasmine.anything().
Material Design Lite
CSS and JavaScript toolkit for applying Google’s Material Design to static websites, but it is incomplete, awkward to use, and can conflict with live reload or JavaScript frameworks.
Single step and slow motion for cucumber scenarios using @javascript selenium
Pause Cucumber browser-driven tests between steps for debugging or demos, with single-step input and slower playback for @javascript Selenium runs.
JavaScript: Working with Query Parameters
Query strings are easier to read and modify with URLSearchParams; it parses, updates, removes, and checks parameters across modern browsers, except IE 11.
Javascript equivalent of Ruby's array.collect(&:method)
Calling a method on every element and collecting the results into a new array has no native JavaScript shorthand; library helpers like pluck fill the gap for property values.
Disable built-in dragging of text and images
Browser text and image dragging can block custom horizontal scrolling or pointer-based movement. Disabling native drag behavior needs CSS and, in Firefox, JavaScript.
JavaScript: How to query the state of a Promise
Native promises do not expose their current state, which makes state checks in unit tests awkward; a promiseState helper can distinguish pending, fulfilled, and rejected promises.
Merging two JavaScript objects
Combining properties from two JavaScript objects depends on the runtime: spread syntax, Object.assign(), or up.util.merge() can create a new object with later values winning.
Convert primitive Ruby structures into Javascript
Ruby values can be embedded safely in Javascript responses by serializing them to JSON, avoiding manual quoting and escaping problems.