Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blockable JS Alerts inside tabs #904

Merged
merged 60 commits into from
Jan 26, 2023
Merged

Conversation

graeme
Copy link
Collaborator

@graeme graeme commented Dec 16, 2022

Task/Issue URL: https://app.asana.com/0/72649045549333/1201615584595450/f
Tech Design URL: https://app.asana.com/0/481882893211075/1203352316751829/f
CC:

Description:

We need to update our JS alerts so that they:

  • are presented on the tab level, preventing spammy alerts from blocking the window
  • allow the user to block additional alerts being shown on that website

Steps to test this PR:
https://privacy-test-pages.glitch.me/features/js-alerts.html

Testing checklist:

  • Test with Release configuration
  • Test proper deallocation of tabs
  • Make sure committed submodule changes are desired

Internal references:

Software Engineering Expectations
Technical Design Template
When ready for review, remember to post the PR in MM

@graeme graeme added the draft label Dec 16, 2022
@graeme graeme force-pushed the graeme/js-alerts-inside-tabs branch from 89afea1 to f6488eb Compare December 16, 2022 20:22
@mallexxx mallexxx self-assigned this Dec 19, 2022
Copy link
Collaborator

@mallexxx mallexxx left a comment

Choose a reason for hiding this comment

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

The code looks fine, good job! 👍
Please see some comments inline

DuckDuckGo/Browser Tab/Model/Tab+Dialogs.swift Outdated Show resolved Hide resolved
DuckDuckGo/Browser Tab/Model/Tab.swift Outdated Show resolved Hide resolved
DuckDuckGo/Browser Tab/Model/Tab.swift Show resolved Hide resolved

// MARK: - Alerts

enum AlertHandlingState {
Copy link
Collaborator

Choose a reason for hiding this comment

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

please let‘s keep the Tab.swift code with minimal changes needed, the alert state can be managed using only the userInteractionDialog property

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not 100% sure about that... but I'll remove the alert blocking functionality now based on your above comment and we can discuss this more if we decide to include that in a later PR


// MARK: - Alerts

private var jsAlertController: JSAlertController?
Copy link
Collaborator

Choose a reason for hiding this comment

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

it seems we don‘t need this extra property here since it‘s held in the closure


private func showAlert(with query: JSAlertQuery) -> AnyCancellable {
jsAlertController = JSAlertController.create(query)
addAndLayoutChild(self.jsAlertController!)
Copy link
Collaborator

Choose a reason for hiding this comment

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

please avoid force unwrapping when not needed, extra let jsAlertController = ..create(); self. jsAlertController = jsAlertController would be fine

@mallexxx mallexxx assigned graeme and unassigned mallexxx Dec 21, 2022
@graeme graeme removed their assignment Dec 21, 2022
@graeme graeme requested a review from mallexxx December 21, 2022 10:57
@graeme graeme force-pushed the graeme/js-alerts-inside-tabs branch 6 times, most recently from f463f60 to 79fd318 Compare December 22, 2022 11:56
import XCTest
@testable import DuckDuckGo_Privacy_Browser

final class JSAlertViewModelTests: XCTestCase {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice 🎉

Bunn
Bunn previously requested changes Jan 13, 2023
Copy link
Collaborator

@Bunn Bunn left a comment

Choose a reason for hiding this comment

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

The code looks good, I think Alex caught all the issues before.
There are some swiftlint rules not being respected that would be good to take a look before merging.

That said I found 2 issues

  • 1/ This is minor, I'd check with design to see if they think it's a blocker, IMO it is a non critical edge case but if the window is really small and then an alert is displayed, it automatically increases the window size. I'll leave it to you to decide if you want to handle this or not.
    See the video:
ResizeBug.mov

  • 2/ The color gets messed up if you change the system from/to light/dark mode. IMO a blocker and the reason I'm setting as request changes.

Screenshot 2023-01-13 at 18 29 02

Screenshot 2023-01-13 at 18 29 18

@Bunn Bunn assigned graeme and unassigned mallexxx Jan 13, 2023
@github-actions
Copy link

github-actions bot commented Jan 16, 2023

Warnings
⚠️ PR has more than 500 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS against 9b42b1d

@graeme graeme force-pushed the graeme/js-alerts-inside-tabs branch from f7d11c6 to 5d41214 Compare January 16, 2023 11:22
@mallexxx
Copy link
Collaborator

I noticed another issue, the button colour doesn‘t match the system accent colour (is always blue)

@graeme graeme assigned Bunn and unassigned graeme Jan 16, 2023
@mallexxx mallexxx assigned mallexxx and unassigned Bunn Jan 17, 2023
Copy link
Collaborator

@mallexxx mallexxx left a comment

Choose a reason for hiding this comment

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

I think that‘s really close, good job!
I‘ve found several issues and we‘re good to go:

  • Alert background isn‘t blocking click events, e.g. Inspector UI elements aren‘t blocked when the alert is displayed, right-clicking background alert displays page context after the alert is hidden
  • Scrolling position (for long text) is not zero at appearance (see screenshot attached)
    Screenshot 2023-01-17 at 14 03 07

Enter key still doesn‘t work properly ☹️ :

  • textField receives gets First Responder even if it‘s hidden
  • after selecting the AddressBar and hitting Esc key Enter won‘t dismiss the alert
  • Esc key doesn‘t dismiss an alert() - it does in Safari
  • I suggest implementing acceptsFirstResponder { true } and handling keys in keyDown handler in the JSAlertController, setting first responder to jsAlertController.view on viewDidAppear.
  • As a fallback for the AddressBar deactivated with Esc key I suggest the following:
        view.window?.observe(\.firstResponder) { window, _ in
            if window.firstResponder is WebView {
                self.view.makeMeFirstResponder()
            }
        }

DuckDuckGo/Common/Extensions/NSTextViewExtension.swift Outdated Show resolved Hide resolved
DuckDuckGo/JSAlert/JSAlert.storyboard Outdated Show resolved Hide resolved
DuckDuckGo/JSAlert/JSAlertController.swift Outdated Show resolved Hide resolved
DuckDuckGo/JSAlert/JSAlertController.swift Outdated Show resolved Hide resolved
DuckDuckGo/JSAlert/JSAlertController.swift Outdated Show resolved Hide resolved
DuckDuckGo/JSAlert/JSAlertController.swift Outdated Show resolved Hide resolved
DuckDuckGo/JSAlert/JSAlertController.swift Outdated Show resolved Hide resolved
DuckDuckGo/JSAlert/JSAlertController.swift Outdated Show resolved Hide resolved
@mallexxx mallexxx assigned graeme and unassigned mallexxx Jan 17, 2023
@mallexxx
Copy link
Collaborator

Another minor thing I noticed is when an empty alert() is shown there‘s an empty place in the displayed alert. I‘m not strong on fixing this though

@graeme graeme force-pushed the graeme/js-alerts-inside-tabs branch from ccb67c7 to c8d9e8a Compare January 24, 2023 12:22
Copy link
Collaborator

@mallexxx mallexxx left a comment

Choose a reason for hiding this comment

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

Scrolling problem still present, it‘s fixed for me if I replace sizeToFit() with view.layoutSubtreeIfNeeded()
.. just wondering can it fix the delayed animation problem either?

Other than that, LGTM!
Approved after fixing the issue

@graeme graeme removed the draft label Jan 24, 2023
@graeme graeme dismissed Bunn’s stale review January 24, 2023 13:16

Alex has taken over

@graeme graeme merged commit c7f54ed into develop Jan 26, 2023
@graeme graeme deleted the graeme/js-alerts-inside-tabs branch January 26, 2023 15:17
samsymons added a commit that referenced this pull request Jan 26, 2023
# By Dominik Kapusta (4) and others
# Via GitHub
* develop:
  Blockable JS Alerts inside tabs (#904)
  Fix add bookmark / folder modal in fullscreen (#930)
  Add Mac App Store target (#927)
  Pull request review checklist added to the pull request template (#935)
  Version Bump to 0.31.7
  Update embedded files
  Update BSK with autofill 6.1.2 (#942)
  Migrate to targeted Swift Concurrency checking (#937)
  Add bundler configuration to limit Gemfile.lock noise (#939)
  update openssl depedency (#918)
  Remove tab content when showing TabContent.none (such as for new tabs opened from navigation links) (#938)
  Update GRDB to 2.0.0 (upstream 6.6.0, SQLCipher 4.5.3) (#933)
  Sparkle 2 (#934)
  Bump Submodules/privacy-reference-tests from `de75d51` to `4fdbbb6` (#932)

# Conflicts:
#	DuckDuckGo.xcodeproj/project.pbxproj
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