Skip to content

Add scope option to grantAccessIfNeeded for page-level tools#28

Closed
sebastianchristopher wants to merge 1 commit into
masterfrom
sebastianchristopher-grant-access-scope-option
Closed

Add scope option to grantAccessIfNeeded for page-level tools#28
sebastianchristopher wants to merge 1 commit into
masterfrom
sebastianchristopher-grant-access-scope-option

Conversation

@sebastianchristopher

Copy link
Copy Markdown
Contributor

Some tools render directly in the page rather than inside an LTI iframe. Previously grantAccessIfNeeded always assumed an iframe context, making it unusable for those tools.

This adds an optional options parameter with two fields:

  • scope ('lti' | 'page') -- controls whether the helper looks inside the LTI iframe (default, backward-compatible) or operates on the top-level page.
  • promptTimeoutMs -- configurable timeout for detecting the "Please Grant Access" prompt (defaults to 3000 ms).

Other small improvements bundled in:

  • Uses .first() on the grant-access button locator to avoid Playwright strict-mode failures when multiple buttons exist.
  • Makes the Authorize regex case-insensitive (/i) so it matches both "Authorize" and "Authorise" regardless of casing.
  • Updates JSDoc types on grantAccess and waitForNoSpinners to accept FrameLocator | Page.

- Add GrantAccessOptions typedef with scope ('lti'|'page') and promptTimeoutMs
- Default to 'lti' for backward compatibility
- When scope is 'page', operate directly on the page instead of the LTI iframe
- Use .first() on button locator to avoid strict-mode failures
- Make Authorize regex case-insensitive
- Update JSDoc types to accept FrameLocator | Page

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an optional scope to grantAccessIfNeeded so deployment tests can support tools that render at the top-level page (not inside the LTI iframe), while keeping the existing default LTI-iframe behavior.

Changes:

  • Add options to grantAccessIfNeeded with scope: 'lti' | 'page' and promptTimeoutMs.
  • Make the LTI “Loading…” wait conditional on scope === 'lti'.
  • Improve locator robustness (.first() on the grant-access button) and broaden matching (/i for Authori[sz]e); update JSDoc types to accept FrameLocator | Page.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/testUtils.js
Comment on lines 43 to 51
const needsGrantAccess = await Promise.race([
ltiToolFrame.getByText('Please Grant Access').waitFor()
scopeRoot.getByText('Please Grant Access').waitFor({
state: 'visible',
timeout: promptTimeoutMs
})
.then(() => { return true }),
waitForNoSpinners(ltiToolFrame, 3000)
waitForNoSpinners(scopeRoot, 3000)
.then(() => { return false })
])
Comment thread src/testUtils.js

await page.goto(toolUrl)
const ltiToolFrame = getLtiIFrame(page)
const scopeRoot = scope === 'lti' ? getLtiIFrame(page) : page

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm slightly confused here as the LTI tool is still displayed in a iframe. Isn't it just the getLtiIFrame() method is looking for a specific iframe which doesn't match this one iframe[data-lti-launch="true"]:

Image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this was the wrong solution. Will do another PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants