Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Ledger timer not starting when changing focus to tabs opened in the background #3716

Closed
da2x opened this issue Sep 4, 2016 · 11 comments
Closed
Assignees
Milestone

Comments

@da2x
Copy link
Contributor

da2x commented Sep 4, 2016

Did you search for similar issues before submitting this one?
Yes

Describe the issue you encountered:
Tabs opened in the background aren’t counted as time nor views.

Expected behavior:
Start counting them as views/time when the tabs are brought to the foreground for the first time.

Platform (Win7, 8, 10? macOS? Linux distro?):
Fedora 24

Brave Version:
0.11.6

Steps to reproduce:
1. Visit Google News and search for bunny rabbits
2. Open two news articles about bunny rabbits as background tabs
3. Switch to the first new background tab and wait 10 seconds
4. Switch to the second new tab and wait 60 seconds
6. Go to about:preferences#payments, the background-tabbed-sites never should up

Alternative steps:
1. Open about:blank in tab A, and ArsTechnica.com in tab B
2. Quickly open two articles in background tabs from Ars and switch to tab A
3. Close tab B (Ars front page)
4. Go to about:preferences#payments and see a few seconds of Arse
5. Open one of the Ars background tabs to the foreground and enjoy some fine journalism
6. Close that tab and go to about:preferences#payments again
7. You’ve consumed the same amount of Ars as on step 4

Notes:
I noticed the issue when none of the sites I had opened from my webmail (FastMail) nor RSS reader (Newsblur) appeared on the Brave Payments page. I rely heavily on background tabs (use it as a reading queue), and this is seriously skewing my contributions. I go to the homepage of websites, open the most interesting articles in background tabs, and then close these tabs one by one as I go through them. The time that is counted, the time I spend on their front pages, is actually entirely insignificant – mere seconds.

@bbondy
Copy link
Member

bbondy commented Sep 4, 2016

@mrose17 pls triage into a milestone

@mrose17 mrose17 added this to the 0.12.1dev milestone Sep 5, 2016
@mrose17
Copy link
Member

mrose17 commented Sep 5, 2016

@Aeyoun - hey there!

just to clarify. my understanding is that the ledger timing should only be ticking for "the top tab in the top window". the reason is that's what you're "supposed" to be looking at. if that's not the behavior you're seeing, then help me understand what you're seeing, so i can make my understanding match the code (-;

by the way, here is how i test for that scenario (on the mac):

    LEDGER_PUBLISHER_DEBUG=true /Applications/Brave.app/Contents/MacOS/Brave

then create a background tab, then go to that tab, then wait 30s and go to another tab, then look for something like this>

    locations[http://www.wsj.com/articles/apples-new-iphones-arrive-as-glow-fades-1473099607]={
    ...
    } duration=30093 msec

one thing to keep in mind is that you have to be on a tab for at least 8 seconds before it gets accounted for. (i'd like to make that amount configurable... what do you think?)

one of these challenges in implementing the ledger client is to deal with the understanding what to actually count count. there are many edge cases that i'd like to deal with, but am not sure how. for example, on the mac, i can scroll a window without having it be active. it may be that the focused app is my twitter client, but i am scrolling around in the browser. i don't know how to account for that right now, but would like to. does that make sense?

thanks!

@da2x
Copy link
Contributor Author

da2x commented Sep 5, 2016

Everything I talked about in the original description was with Brave as the active/focused/topmost window. To sum up what I said: "Tabs opened in the background don’t start counting when I click on them and make them the foreground/active/topmost tab."

I’m not saying I think tabs that are opened and stay in the background should count. I’m saying that the count should start counting when I make these background tab the active tab. This doesn’t happen in the latest released build. Tabs that are opened in the background never start counting in the ledger even when they’re the only tab left opened in the browser.

After spending three minuets on it, I’d suspect the culprit is in WINDOW_WEBVIEW_LOAD_END in eventStore.js. When the tab finishes its loading in the background it pushes some data to eventState but as it hasn’t called addPageView() the state in eventState is different to that it would be for a tab opened in the foreground (and foreground tabs work). I could of course be way off here.

example, on the mac, i can scroll a window without having it be active. it may be that the focused app is my twitter client, but i am scrolling around in the browser. i don't know how to account for that right now, but would like to. does that make sense?

macOS native code actually have got you covered on this. I don’t remember the name of the API of the top of my head, but when 70% of a window is visible on screen, then there is either an event or a property of the window object that says that the window is considered to be active (but not focused). No idea how to solve that for other platforms nor how to solve it without relying on macOS native code, but their logic is sensible enough.

@mrose17
Copy link
Member

mrose17 commented Sep 5, 2016

sorry, my bad. i just did some editing to reflect what you wrote!

@mrose17
Copy link
Member

mrose17 commented Sep 5, 2016

just so i'm clear, you are waiting at least 8 seconds?

@bridiver - can you take a look at the comment above about WINDOW_WEBVIEW_LOAD_END ? thanks!

@da2x
Copy link
Contributor Author

da2x commented Sep 5, 2016

I’ve waited 120 seconds and used a stopwatch. :)

@bridiver
Copy link
Collaborator

bridiver commented Sep 5, 2016

WINDOW_WEBVIEW_LOAD_END is not really relevant here because that is primarily for page load events. It only generates a page view if it's the active tab. The primary method for adding page view events is WINDOW_SET_FOCUSED_FRAME

@da2x
Copy link
Contributor Author

da2x commented Sep 6, 2016

I’m really not understanding what is happening. It happens more often when I use background tabs, but I’ve now seen the same thing with foreground tabs. It’s possibly related to me clicking away from the front page and into articles quickly (before 8 seconds). I’m not really sure, though. LEDGER_PUBLISHER_DEBUG looks the same for websites when the counter works and for sites where it doesn't work. It’s 3am now and I’ll look into this again tomorrow afternoon.

@mrose17
Copy link
Member

mrose17 commented Sep 6, 2016

@Aeyoun - let's wait until the next beta is out and we can try on that... good night!

@da2x
Copy link
Contributor Author

da2x commented Sep 6, 2016

Resolved by #3696.

@luixxiul
Copy link
Contributor

For QA note: #3696 is not yet closed as I write this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants