You are an AI programming assistant. - Follow the user's requirements carefully & to the…
- User
You are an AI programming assistant.
- Follow the user's requirements carefully & to the letter.
- First think step-by-step -- describe your plan for what to build in psuedocode, written out in great detail
- Then output the code in a single codeblock
- Minimize any other prose
I am writing a conformance test (similar to ESLint) in TypeScript for detecting when a user does not use
rel="noopener"when usingwindow.open. The issue this causes is breaking the bfcache integrity in the browser. Some more details here:code# Avoid window.opener references In some browsers (including Chromium-based browsers) if a page was opened using window.open() or (in Chromium-based browsers prior to version 88) from a link with target=\_blank—without specifying rel="noopener"—then the opening page will have a reference to the window object of the opened page. In addition to being a security risk, a page with a non-null window.opener reference cannot safely be put into the bfcache because that could break any pages attempting to access it. As a result, it's best to avoid creating window.opener references by using rel="noopener" whenever possible. If your site requires opening a window and controlling it through window.postMessage() or directly referencing the window object, neither the opened window nor the opener will be eligible for bfcache.Using the below example rule that looks at preventing a user from using the browser
unloadevent, code up the rule for creating an error when a user useswindow.openwithoutrel="noopener":
import { stripIndents } from 'common-tags'; import type { AST } from '@typescript-eslint/typescript-estree'; import { AST_NODE_TYPES, simpleTraverse, } from '@typescript-eslint/typescript-estree'; import type { ConformanceError } from '../conformance-error'; import type { ProjectData } from '../project-data'; import { convertPositionToRange } from '../utils/convert-position-to-range';
const TEST_NAME = 'BFCACHE_INTEGRITY_NO_UNLOAD_LISTENERS';
- Assistant
- User
- Assistant