One thing you have to credit Will Smith for, some of his projects seem head-scratching, but the man plays the long game.
Among film geeks he is famous for having pissed away his earnings from his days as The Fresh Prince alongside DJ Jazzy Jeff, and subsequently rescued by Quincy Jones who plopped him on television for six seasons.
In the time since then, he tends to select projects based not only on their US appeal but also for their potential draw in international theaters. So sometimes a movie won't do well here but will be gangbusters overseas. Altogether, his US box office only accounts for a third of his worldwide box; take those theaters into account and he is literally a six billion dollar man.
WWW wasn't hugely successful here or overseas but did gross $220m in total, which is nowhere near his highest amount, but still nothing to sneeze at. His two subsequent roles, Bagger Vance and Ali, combine to only bring in half that amount.
So not everybody can choose all the best roles all the time, and Smith is no exception, but he's smart enough in controlling his brand that he has all the money he'll ever need, and globally, he was (is?) one of the single most popular movie stars of a generation.