惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
T
Threatpost
T
Tor Project blog
S
Schneier on Security
Project Zero
Project Zero
Know Your Adversary
Know Your Adversary
P
Proofpoint News Feed
K
Kaspersky official blog
P
Privacy International News Feed
Latest news
Latest news
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
The Hacker News
The Hacker News
D
Docker
aimingoo的专栏
aimingoo的专栏
S
Securelist
C
Cyber Attacks, Cyber Crime and Cyber Security
Spread Privacy
Spread Privacy
TaoSecurity Blog
TaoSecurity Blog
T
The Blog of Author Tim Ferriss
T
Threat Research - Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
博客园 - 三生石上(FineUI控件)
人人都是产品经理
人人都是产品经理
Security Latest
Security Latest
V
Visual Studio Blog
WordPress大学
WordPress大学
J
Java Code Geeks
O
OpenAI News
T
Tailwind CSS Blog
S
Secure Thoughts
G
Google Developers Blog
博客园_首页
The Cloudflare Blog
The Register - Security
The Register - Security
A
Arctic Wolf
Y
Y Combinator Blog
阮一峰的网络日志
阮一峰的网络日志
B
Blog RSS Feed
IT之家
IT之家
美团技术团队
D
Darknet – Hacking Tools, Hacker News & Cyber Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
G
GRAHAM CLULEY
S
Security Affairs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Application and Cybersecurity Blog
Application and Cybersecurity Blog
P
Palo Alto Networks Blog
C
CERT Recently Published Vulnerability Notes
W
WeLiveSecurity

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Opening Pandora's Box: How to Unlock Direct DOM Method Calls in Blazor, No External JS File Needed
jsakamoto · 2026-06-13 · via DEV Community

🔰 Referencing and operating DOM elements in Blazor

In Blazor, you can reference a DOM element that a component has rendered by using the ElementReference type.

<input type="text" @ref="_inputElement">...</input>

@code {
    private ElementReference _inputElement;
}

The reference you get this way is handy. You can pass it as an argument when you call a JavaScript function or method from the Blazor side, using the JavaScript interop feature. The ElementReference type also gives you a FocusAsync() extension method, which lets you set focus on the DOM element it points to.


🤔 The limit, and the pain

But what if you want to do more than just setting focus? Say you want to call DOM methods like click, select, or scrollIntoView. Normally, you have to create an external JavaScript file, define a proper function there, and call it from the Blazor side.

Let me show you what that looks like. First, you create a JavaScript file like this.

// wwwroot/js/elementMethods.js
export const scrollIntoView = (element, options) => element.scrollIntoView(options);

Then, to call this function from Blazor, you import the JavaScript module using IJSRuntime and call the function from it.

@inject IJSRuntime JSRuntime
...
<input type="text" @ref="_inputElement">...</input>
...
@code {
    private ElementReference _inputElement;

    private async Task ScrollIntoView()
    {
        await using var module = await JSRuntime.InvokeAsync<IJSObjectReference>("import", "./js/elementMethods.js");
        await module.InvokeVoidAsync("scrollIntoView", _inputElement, new { behavior = "smooth" });
    }
}

Honestly, having to create an external JavaScript file just to do a tiny DOM operation is painful. You think, "ah, I just want to scroll to this element," or "I just want to select this element," and then you have to stop and go create a JavaScript file. That breaks your flow every single time.

Sure, these days we often let an AI agent write the code, so maybe this is less of a big deal. But here's the thing: during human code review or quick fixes, jumping back and forth between the .razor and .js files, and keeping the two in sync, is still a real hassle.


🤷 Many Issues raised, all of them closed

This problem is not new. Since 2019, people have opened improvement request Issues to the ASP.NET Core team many times.

2019
#6937 [Blazor] Direct DOM Manipulation with C#

2020
#24734 JSInterop for properties and element methods
#25685 Get IJSObjectReference from ElementReference

2021
#28820 DOM API Bindings and Blazor support
#29823 New properties for ElementReference (SelectAllAsync, GetBoundingRectangleAsync)
#29826 Expose IJSRuntime instance through ElementReference

2023
#47197 Expose internal JSRuntime in ElementReference for static extensions

2024
#61488 Add interop API to ElementReference

And yet, every single one of these Issues was closed with the same answer: "we will not support this." The reasons go something like this:

  • If it becomes too easy to call methods from a DOM element reference, code that touches the DOM directly will grow, and that invites performance problems.
  • It risks breaking Blazor's abstraction layer and damaging the DOM model.

Fair enough. The ASP.NET Core team's reasoning makes sense. But even so, not being able to do even a tiny DOM operation without an external JavaScript file is still tough.


💡 There was a way to call it directly!

Now, here is an interesting fact. In Blazor's JavaScript interop, you can receive a reference to any JavaScript object as an IJSObjectReference on the Blazor side, and then call its methods. And a DOM element in the browser is, from JavaScript's point of view, ultimately just an object too.

So that got me thinking.

If I could convert an ElementReference into an IJSObjectReference without an external JavaScript file, then I could call DOM methods directly, all within the .razor file alone. Right?

I brought this idea to an AI chat, and it told me something neat: "The browser built-in Object() function returns the object you pass to it as is (boxing). So you can use it to convert an ElementReference into an IJSObjectReference." I tried it right away, and it worked beautifully! It almost felt too easy 😅

Here is the code.

@inject IJSRuntime JSRuntime
...
<input type="text" @ref="_inputElement">...</input>
...
@code {
    private ElementReference _inputElement;

    private async Task ScrollIntoView()
    {
        // Pass the ElementReference to JavaScript's Object() function
        // to "convert" it into an IJSObjectReference
        await using var inputJsObj = await JSRuntime.InvokeAsync<IJSObjectReference>("Object", _inputElement);

        // After converting, you can call DOM methods directly without any external .js file!
        await inputJsObj.InvokeVoidAsync("scrollIntoView", new { behavior = "smooth" });
    }
}

With this technique, you can call any method of the referenced DOM element from inside the .razor file alone. No need to create or edit an external JavaScript file. That cuts down a lot of friction when you just want a small DOM operation. You no longer leave the .razor file and travel back and forth to the .js file while you work.


🔍 A related approach

I am not the first to chase this idea. A similar technique, calling DOM element methods from the .razor file alone without an external JavaScript file, was introduced in a nice article back in 2024.

Say goodbye to JavaScript in your Blazor web app | My Reality

Uni is taking too much of my time, and so I cannot work much on Project Reality and lxmonika.

favicon trungnt2910.com

The method in that article does not call the method straight from the DOM element reference. Instead, it goes through the prototype of the HTML element. What you can do is the same in the end. But I think the Object() function approach shown here is shorter and a bit more intuitive to write.


⚠️ Things to watch out for

I really do think this technique, converting an ElementReference into an IJSObjectReference with Object() and calling DOM methods directly, is convenient and useful. Still, I want to be honest about the trade-offs. The ASP.NET Core team kept raising the same concerns in those Issues, and those concerns are real. Careless use can lead to problems like "it was fine in development, but performance dropped in production," or damage to the DOM model from skipping Blazor's abstraction layer.

On top of that, this technique has a few specific points to keep in mind:

  • Compared to the Say goodbye to JavaScript in your Blazor web app method above, it needs one extra JavaScript interop call to do the conversion into IJSObjectReference.
  • If you forget to dispose of the IJSObjectReference, you get a memory leak.
  • After the conversion, even if a re-render changes the target DOM element, the IJSObjectReference keeps pointing at the now detached DOM element.

So please use this only when you are sure it will cause no problem, and do not overuse it. In particular, avoid it in code that may run often, or in code where performance matters. Sharing this technique in custom instructions or skills for your team or your AI agents is a good idea, but I think you should also make the rules for its use clear at the same time.


🎉 Wrap-up

I showed you a technique that converts a Blazor ElementReference into an IJSObjectReference using the browser built-in Object() function. With it, you can call any method of a DOM element from inside the .razor file alone, with no external JavaScript file. Just remember the concerns the ASP.NET Core team raised, and avoid careless overuse.

That said, this little trick is genuinely handy when you want a quick DOM operation. Part of me still wishes the Blazor team would relax this a bit on the official side. But for now, I will happily keep my Blazor development smooth with this workaround.

If you know of other approaches or have updates to share, please drop them in the comments! 👇

❤️ Happy coding!